From 946413dd88aa49afe693775d6bc0cd0c40f118c5 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 11 Mar 2011 10:23:23 -0800 Subject: [PATCH] Remove outdated thridparty pacakge --- thirdparty/nbench-byte-2.2.3/COM.DAT | 11 - thirdparty/nbench-byte-2.2.3/Changes | 42 - thirdparty/nbench-byte-2.2.3/Makefile | 153 - thirdparty/nbench-byte-2.2.3/NNET.DAT | 210 - thirdparty/nbench-byte-2.2.3/README | 66 - thirdparty/nbench-byte-2.2.3/README.motorola | 29 - thirdparty/nbench-byte-2.2.3/README.nonlinux | 50 - thirdparty/nbench-byte-2.2.3/README.submit | 33 - thirdparty/nbench-byte-2.2.3/RESULTS | 138 - thirdparty/nbench-byte-2.2.3/bdoc.txt | 2109 -------- thirdparty/nbench-byte-2.2.3/debugbit.good.gz | Bin 1019 -> 0 bytes thirdparty/nbench-byte-2.2.3/emfloat.c | 1343 ----- thirdparty/nbench-byte-2.2.3/emfloat.h | 154 - thirdparty/nbench-byte-2.2.3/hardware | Bin 17013 -> 0 bytes thirdparty/nbench-byte-2.2.3/hardware.c | 202 - thirdparty/nbench-byte-2.2.3/hardware.h | 2 - thirdparty/nbench-byte-2.2.3/hello.c | 2 - thirdparty/nbench-byte-2.2.3/misc.c | 120 - thirdparty/nbench-byte-2.2.3/misc.h | 41 - thirdparty/nbench-byte-2.2.3/nbench0.c | 1190 ----- thirdparty/nbench-byte-2.2.3/nbench0.h | 356 -- thirdparty/nbench-byte-2.2.3/nbench1.c | 4445 ----------------- thirdparty/nbench-byte-2.2.3/nbench1.h | 428 -- thirdparty/nbench-byte-2.2.3/nmglobal.h | 519 -- thirdparty/nbench-byte-2.2.3/pointer.c | 6 - .../nbench-byte-2.2.3/sysinfo.c.example | 10 - .../nbench-byte-2.2.3/sysinfo.c.template | 10 - thirdparty/nbench-byte-2.2.3/sysinfo.sh | 78 - .../nbench-byte-2.2.3/sysinfoc.c.example | 4 - .../nbench-byte-2.2.3/sysinfoc.c.template | 4 - thirdparty/nbench-byte-2.2.3/sysspec.c | 884 ---- thirdparty/nbench-byte-2.2.3/sysspec.h | 168 - thirdparty/nbench-byte-2.2.3/wordcat.h | 81 - thirdparty/snark/AUTHORS | 2 - thirdparty/snark/COPYING | 340 -- thirdparty/snark/ChangeLog | 487 -- thirdparty/snark/Makefile | 85 - thirdparty/snark/README | 141 - thirdparty/snark/TODO | 22 - thirdparty/snark/build.xml | 214 - thirdparty/snark/lib/LIBS | 4 - thirdparty/snark/lib/manifest-gtk.mf | 1 - thirdparty/snark/lib/manifest.mf | 1 - thirdparty/snark/libs-incl.xml | 7 - thirdparty/snark/snark-gnome.sh | 8 - .../src/java/org/klomp/snark/BitField.java | 143 - .../org/klomp/snark/ConnectionAcceptor.java | 146 - .../org/klomp/snark/CoordinatorListener.java | 33 - .../java/org/klomp/snark/HttpAcceptor.java | 245 - .../src/java/org/klomp/snark/Message.java | 156 - .../src/java/org/klomp/snark/MetaInfo.java | 389 -- .../snark/src/java/org/klomp/snark/Peer.java | 393 -- .../java/org/klomp/snark/PeerAcceptor.java | 54 - .../java/org/klomp/snark/PeerCheckerTask.java | 187 - .../org/klomp/snark/PeerConnectionIn.java | 150 - .../org/klomp/snark/PeerConnectionOut.java | 319 -- .../java/org/klomp/snark/PeerCoordinator.java | 498 -- .../src/java/org/klomp/snark/PeerID.java | 210 - .../java/org/klomp/snark/PeerListener.java | 166 - .../java/org/klomp/snark/PeerMonitorTask.java | 130 - .../src/java/org/klomp/snark/PeerState.java | 481 -- .../src/java/org/klomp/snark/Request.java | 83 - .../org/klomp/snark/ShutdownListener.java | 34 - .../snark/src/java/org/klomp/snark/Snark.java | 380 -- .../java/org/klomp/snark/SnarkShutdown.java | 83 - .../src/java/org/klomp/snark/StaticSnark.java | 52 - .../src/java/org/klomp/snark/Storage.java | 519 -- .../java/org/klomp/snark/StorageListener.java | 51 - .../src/java/org/klomp/snark/Tracker.java | 202 - .../java/org/klomp/snark/TrackerClient.java | 258 - .../src/java/org/klomp/snark/TrackerInfo.java | 131 - .../org/klomp/snark/bencode/BDecoder.java | 358 -- .../java/org/klomp/snark/bencode/BEValue.java | 172 - .../org/klomp/snark/bencode/BEncoder.java | 171 - .../bencode/InvalidBEncodingException.java | 36 - .../snark/cmd/ConsoleStorageReporter.java | 73 - .../org/klomp/snark/cmd/SnarkApplication.java | 293 -- .../snark/tracker/TrackerApplication.java | 138 - thirdparty/virtualdns/ErrorMessages.java | 73 - thirdparty/virtualdns/VirtualDNS.java | 311 -- thirdparty/virtualdns/build.sh | 1 - thirdparty/virtualdns/log4j.properties | 18 - thirdparty/virtualdns/named.realhostip.com | 19 - thirdparty/virtualdns/run.sh | 1 - 84 files changed, 21357 deletions(-) delete mode 100644 thirdparty/nbench-byte-2.2.3/COM.DAT delete mode 100644 thirdparty/nbench-byte-2.2.3/Changes delete mode 100644 thirdparty/nbench-byte-2.2.3/Makefile delete mode 100644 thirdparty/nbench-byte-2.2.3/NNET.DAT delete mode 100644 thirdparty/nbench-byte-2.2.3/README delete mode 100644 thirdparty/nbench-byte-2.2.3/README.motorola delete mode 100644 thirdparty/nbench-byte-2.2.3/README.nonlinux delete mode 100644 thirdparty/nbench-byte-2.2.3/README.submit delete mode 100644 thirdparty/nbench-byte-2.2.3/RESULTS delete mode 100644 thirdparty/nbench-byte-2.2.3/bdoc.txt delete mode 100644 thirdparty/nbench-byte-2.2.3/debugbit.good.gz delete mode 100644 thirdparty/nbench-byte-2.2.3/emfloat.c delete mode 100644 thirdparty/nbench-byte-2.2.3/emfloat.h delete mode 100644 thirdparty/nbench-byte-2.2.3/hardware delete mode 100644 thirdparty/nbench-byte-2.2.3/hardware.c delete mode 100644 thirdparty/nbench-byte-2.2.3/hardware.h delete mode 100644 thirdparty/nbench-byte-2.2.3/hello.c delete mode 100644 thirdparty/nbench-byte-2.2.3/misc.c delete mode 100644 thirdparty/nbench-byte-2.2.3/misc.h delete mode 100644 thirdparty/nbench-byte-2.2.3/nbench0.c delete mode 100644 thirdparty/nbench-byte-2.2.3/nbench0.h delete mode 100644 thirdparty/nbench-byte-2.2.3/nbench1.c delete mode 100644 thirdparty/nbench-byte-2.2.3/nbench1.h delete mode 100644 thirdparty/nbench-byte-2.2.3/nmglobal.h delete mode 100644 thirdparty/nbench-byte-2.2.3/pointer.c delete mode 100644 thirdparty/nbench-byte-2.2.3/sysinfo.c.example delete mode 100644 thirdparty/nbench-byte-2.2.3/sysinfo.c.template delete mode 100644 thirdparty/nbench-byte-2.2.3/sysinfo.sh delete mode 100644 thirdparty/nbench-byte-2.2.3/sysinfoc.c.example delete mode 100644 thirdparty/nbench-byte-2.2.3/sysinfoc.c.template delete mode 100644 thirdparty/nbench-byte-2.2.3/sysspec.c delete mode 100644 thirdparty/nbench-byte-2.2.3/sysspec.h delete mode 100644 thirdparty/nbench-byte-2.2.3/wordcat.h delete mode 100644 thirdparty/snark/AUTHORS delete mode 100644 thirdparty/snark/COPYING delete mode 100644 thirdparty/snark/ChangeLog delete mode 100644 thirdparty/snark/Makefile delete mode 100644 thirdparty/snark/README delete mode 100644 thirdparty/snark/TODO delete mode 100644 thirdparty/snark/build.xml delete mode 100644 thirdparty/snark/lib/LIBS delete mode 100644 thirdparty/snark/lib/manifest-gtk.mf delete mode 100644 thirdparty/snark/lib/manifest.mf delete mode 100644 thirdparty/snark/libs-incl.xml delete mode 100644 thirdparty/snark/snark-gnome.sh delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/BitField.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/ConnectionAcceptor.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/CoordinatorListener.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/HttpAcceptor.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/Message.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/MetaInfo.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/Peer.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/PeerAcceptor.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/PeerCheckerTask.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/PeerConnectionIn.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/PeerConnectionOut.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/PeerCoordinator.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/PeerID.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/PeerListener.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/PeerMonitorTask.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/PeerState.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/Request.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/ShutdownListener.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/Snark.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/SnarkShutdown.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/StaticSnark.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/Storage.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/StorageListener.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/Tracker.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/TrackerClient.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/TrackerInfo.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/bencode/BDecoder.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/bencode/BEValue.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/bencode/BEncoder.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/bencode/InvalidBEncodingException.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/cmd/ConsoleStorageReporter.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/cmd/SnarkApplication.java delete mode 100644 thirdparty/snark/src/java/org/klomp/snark/tracker/TrackerApplication.java delete mode 100644 thirdparty/virtualdns/ErrorMessages.java delete mode 100644 thirdparty/virtualdns/VirtualDNS.java delete mode 100755 thirdparty/virtualdns/build.sh delete mode 100644 thirdparty/virtualdns/log4j.properties delete mode 100644 thirdparty/virtualdns/named.realhostip.com delete mode 100755 thirdparty/virtualdns/run.sh diff --git a/thirdparty/nbench-byte-2.2.3/COM.DAT b/thirdparty/nbench-byte-2.2.3/COM.DAT deleted file mode 100644 index 8dee49c3a13..00000000000 --- a/thirdparty/nbench-byte-2.2.3/COM.DAT +++ /dev/null @@ -1,11 +0,0 @@ -ALLSTATS=T -DONUMSORT=T -DOSTRINGSORT=T -DOBITFIELD=T -DOEMF=T -DOFOUR=T -DOASSIGN=T -DOIDEA=T -DOHUFF=T -DONNET=T -DOLU=T diff --git a/thirdparty/nbench-byte-2.2.3/Changes b/thirdparty/nbench-byte-2.2.3/Changes deleted file mode 100644 index 111d8bd4ed7..00000000000 --- a/thirdparty/nbench-byte-2.2.3/Changes +++ /dev/null @@ -1,42 +0,0 @@ -This is about BYTE's beta version of the native-algorithm benchmark - -December 16, 1996: - -The source for DOS is obtainable at http://www.byte.com/bmark/bmark.htm -Linux adaptation written by Uwe F. Mayer - -February 7, 1997: - -added -DSOLARIS flag to support solaris - -November 11, 1997: - -added index split suggested by Andrew D. Balsa -re-baselined to a Linux machine -added checking of CPU-type at run-time (cpuinfo.c) -increased maximal number of loops in some tests -removed -DSOLARIS flag, works now automatically (this also removed the - compiler warnings about redefined types and leads to a 20% faster - code for "Bitfield" if compiled with -funroll-loops!) - -November 13-19, 1997: - -changed debugging information -changed random number generator to be always 32 bits even on 64 bit OSs -added data resets to Bitfield and Huffman -created this Changes file -added debug code for Bitfield - -December 6, 1997: - -got rid of cpuinfo.c -added a RESULTS file - -December 7, 1997: - -fixed the statistical analysis used to compute the confidence coefficient -fixed a bug in the DEBUG routine of "Assignment" - -December 11, 1997 -added some entries to RESULTS - diff --git a/thirdparty/nbench-byte-2.2.3/Makefile b/thirdparty/nbench-byte-2.2.3/Makefile deleted file mode 100644 index 5045c779b48..00000000000 --- a/thirdparty/nbench-byte-2.2.3/Makefile +++ /dev/null @@ -1,153 +0,0 @@ -# Makefile for nbench, December 11, 1997, Uwe F. Mayer -# Updated February 18, 2003 - -default: nbench - -########################################################################## -# If you are using gcc-2.7.2.3 or earlier: -# The optimizer of gcc has a bug and in general you should not specify -# -funroll-loops together with -O (or -O2, -O3, etc.) -# This bug is supposed to be fixed with release 2.8 of gcc. -# -# This bug does NOT seem to have an effect on the correct compilation -# of this benchmark suite on my Linux box. However, it leads to -# the dreaded "internal compiler error" message on our alpha -# running DEC Unix 4.0b. The Linux-binary that was used to obtain -# the baseline results was nevertheless compiled with -# CFLAGS = -s -static -Wall -O3 -fomit-frame-pointer -funroll-loops -# -# You should leave -static in the CFLAGS so that your sysinfo can be -# compiled into the executable. - -CC = gcc - -# generic options for gcc -CFLAGS = -s -static -Wall -O3 - -# if your gcc lets you do it, then try this one -#CFLAGS = -s -static -Wall -O3 -fomit-frame-pointer -funroll-loops - -# for gcc on an older Pentium type processor you can try the following -#CFLAGS = -s -static -O3 -fomit-frame-pointer -Wall -m486 \ -# -fforce-addr -fforce-mem -falign-loops=2 -falign-functions=2 \ -# -falign-jumps=2 -funroll-loops - -# for a newer gcc on a newer Pentium type processor you can try the following -#CFLAGS = -s -static -O3 -fomit-frame-pointer -Wall -march=i686 \ -# -fforce-addr -fforce-mem -falign-loops=2 -falign-functions=2 \ -# -falign-jumps=2 -funroll-loops - -# for a newer gcc on an Athlon XP type processor you can try the following -#CFLAGS = -s -static -O3 -fomit-frame-pointer -Wall -march=athlon-xp \ -# -fforce-addr -fforce-mem -falign-loops=2 -falign-functions=2 \ -# -falign-jumps=2 -funroll-loops - -# For debugging using gcc -#CFLAGS = -g -O3 -Wall -DDEBUG - -########################################################################## -# For Linux machines with more than one binary format. -# The default binaries, depends on your system whether it's elf or aout. -MACHINE= -# a.out code for linux on an elf machine -#MACHINE= -bi486-linuxaout -# elf code for linux on an a.out machine -#MACHINE= -bi486-linuxelf -# if you want a different compiler version and different binaries, for example -#MACHINE= -V2.7.2 -bi486-linuxaout - -########################################################################## -# Read the file README.nonlinux if you are not using Linux - -# for DEC Unix using cc you can try -#CC = cc -#CFLAGS = -O3 -#LINKFLAGS = -s -non_shared - -# for SunOS using cc -#CC = cc -#CFLAGS = -O3 -s - -# for DEC Ultrix using cc -#CC = cc -#CFLAGS = -O2 -#LINKFLAGS = -s - -# for a Mac with OsX and the Darwin environment -#CC = cc -#CFLAGS = -O3 -DOSX - -# For debugging using cc -#CC = cc -#CFLAGS = -g -DDEBUG - -########################################################################## -# If your system does not understand the system command "uname -s -r" -# then comment this out - -# NO_UNAME= -DNO_UNAME - -########################################################################## -# For any Unix flavor you need -DLINUX -# You also need -DLINUX to get the new indices - -DEFINES= -DLINUX $(NO_UNAME) - -########################################################################## -# For LINUX-like systems with gcc -sysinfoc.c: Makefile - ./sysinfo.sh $(CC) $(MACHINE) $(DEFINES) $(CFLAGS) - -sysinfo.c: Makefile - ./sysinfo.sh $(CC) $(MACHINE) $(DEFINES) $(CFLAGS) - -########################################################################## -# For non-LINUX systems -# Edit the files sysinfo.c and sysinfoc.c to include your system information -# and take sysinfo.c and sysinfoc.c out of the dependencies for nbench0.o - -hardware.o: hardware.c hardware.h Makefile - $(CC) $(MACHINE) $(DEFINES) $(CFLAGS)\ - -c hardware.c - -nbench0.o: nbench0.h nbench0.c nmglobal.h pointer.h hardware.h\ - Makefile sysinfo.c sysinfoc.c - $(CC) $(MACHINE) $(DEFINES) $(CFLAGS)\ - -c nbench0.c - -emfloat.o: emfloat.h emfloat.c nmglobal.h pointer.h Makefile - $(CC) $(MACHINE) $(DEFINES) $(CFLAGS)\ - -c emfloat.c - -pointer.h: pointer Makefile - $(CC) $(MACHINE) $(DEFINES) $(CFLAGS)\ - -o pointer pointer.c - rm -f pointer.h - if [ "4" = `./pointer` ] ; then touch pointer.h ;\ - else echo "#define LONG64" >pointer.h ; fi - -misc.o: misc.h misc.c Makefile - $(CC) $(MACHINE) $(DEFINES) $(CFLAGS)\ - -c misc.c - -nbench1.o: nbench1.h nbench1.c wordcat.h nmglobal.h pointer.h Makefile - $(CC) $(MACHINE) $(DEFINES) $(CFLAGS)\ - -c nbench1.c - -sysspec.o: sysspec.h sysspec.c nmglobal.h pointer.h Makefile - $(CC) $(MACHINE) $(DEFINES) $(CFLAGS)\ - -c sysspec.c - -nbench: emfloat.o misc.o nbench0.o nbench1.o sysspec.o hardware.o - $(CC) $(MACHINE) $(DEFINES) $(CFLAGS) $(LINKFLAGS)\ - emfloat.o misc.o nbench0.o nbench1.o sysspec.o hardware.o\ - -o nbench -lm - -########################################################################## - -clean: - - /bin/rm -f *.o *~ \#* core a.out hello sysinfo.c sysinfoc.c \ - bug pointer pointer.h debugbit.dat - -mrproper: clean - - /bin/rm -f nbench diff --git a/thirdparty/nbench-byte-2.2.3/NNET.DAT b/thirdparty/nbench-byte-2.2.3/NNET.DAT deleted file mode 100644 index 5711730d934..00000000000 --- a/thirdparty/nbench-byte-2.2.3/NNET.DAT +++ /dev/null @@ -1,210 +0,0 @@ -5 7 8 -26 -0 0 1 0 0 -0 1 0 1 0 -1 0 0 0 1 -1 0 0 0 1 -1 1 1 1 1 -1 0 0 0 1 -1 0 0 0 1 -0 1 0 0 0 0 0 1 -1 1 1 1 0 -1 0 0 0 1 -1 0 0 0 1 -1 1 1 1 0 -1 0 0 0 1 -1 0 0 0 1 -1 1 1 1 0 -0 1 0 0 0 0 1 0 -0 1 1 1 0 -1 0 0 0 1 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 1 -0 1 1 1 0 -0 1 0 0 0 0 1 1 -1 1 1 1 0 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 1 1 1 0 -0 1 0 0 0 1 0 0 -1 1 1 1 1 -1 0 0 0 0 -1 0 0 0 0 -1 1 1 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 1 1 1 1 -0 1 0 0 0 1 0 1 -1 1 1 1 1 -1 0 0 0 0 -1 0 0 0 0 -1 1 1 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 -0 1 0 0 0 1 1 0 -0 1 1 1 0 -1 0 0 0 1 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 1 1 -1 0 0 0 1 -0 1 1 1 0 -0 1 0 0 0 1 1 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 1 1 1 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -0 1 0 0 1 0 0 0 -0 1 1 1 0 -0 0 1 0 0 -0 0 1 0 0 -0 0 1 0 0 -0 0 1 0 0 -0 0 1 0 0 -0 1 1 1 0 -0 1 0 0 1 0 0 1 -0 0 0 0 1 -0 0 0 0 1 -0 0 0 0 1 -0 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -0 1 1 1 0 -0 1 0 0 1 0 1 0 -1 0 0 0 1 -1 0 0 1 0 -1 0 1 0 0 -1 1 0 0 0 -1 0 1 0 0 -1 0 0 1 0 -1 0 0 0 1 -0 1 0 0 1 0 1 1 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 1 1 1 1 -0 1 0 0 1 1 0 0 -1 0 0 0 1 -1 1 0 1 1 -1 0 1 0 1 -1 0 1 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -0 1 0 0 1 1 0 1 -1 0 0 0 1 -1 1 0 0 1 -1 0 1 0 1 -1 0 1 0 1 -1 0 1 0 1 -1 0 0 1 1 -1 0 0 0 1 -0 1 0 0 1 1 1 0 -0 1 1 1 0 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -0 1 1 1 0 -0 1 0 0 1 1 1 1 -1 1 1 1 0 -1 0 0 0 1 -1 0 0 0 1 -1 1 1 1 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 -0 1 0 1 0 0 0 0 -0 1 1 1 0 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 1 0 1 -1 0 0 1 1 -0 1 1 1 1 -0 1 0 1 0 0 0 1 -1 1 1 1 0 -1 0 0 0 1 -1 0 0 0 1 -1 1 1 1 0 -1 0 1 0 0 -1 0 0 1 0 -1 0 0 0 1 -0 1 0 1 0 0 1 0 -0 1 1 1 1 -1 0 0 0 0 -1 0 0 0 0 -0 1 1 1 0 -0 0 0 0 1 -0 0 0 0 1 -1 1 1 1 0 -0 1 0 1 0 0 1 1 -1 1 1 1 1 -0 0 1 0 0 -0 0 1 0 0 -0 0 1 0 0 -0 0 1 0 0 -0 0 1 0 0 -0 0 1 0 0 -0 1 0 1 0 1 0 0 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -0 1 1 1 0 -0 1 0 1 0 1 0 1 -1 0 0 0 1 -1 0 0 0 1 -0 1 0 1 0 -0 1 0 1 0 -0 1 0 1 0 -0 1 0 1 0 -0 0 1 0 0 -0 1 0 1 0 1 1 0 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 1 0 1 -1 0 1 0 1 -1 0 1 0 1 -0 1 0 1 0 -0 1 0 1 0 1 1 1 -1 0 0 0 1 -0 1 0 1 0 -0 1 0 1 0 -0 0 1 0 0 -0 1 0 1 0 -0 1 0 1 0 -1 0 0 0 1 -0 1 0 1 1 0 0 0 -1 0 0 0 1 -0 1 0 1 0 -0 1 0 1 0 -0 0 1 0 0 -0 0 1 0 0 -0 0 1 0 0 -0 0 1 0 0 -0 1 0 1 1 0 0 1 -1 1 1 1 1 -0 0 0 1 0 -0 0 0 1 0 -0 0 1 0 0 -0 1 0 0 0 -0 1 0 0 0 -1 1 1 1 1 -0 1 0 1 1 0 1 0 diff --git a/thirdparty/nbench-byte-2.2.3/README b/thirdparty/nbench-byte-2.2.3/README deleted file mode 100644 index 6863d46fe99..00000000000 --- a/thirdparty/nbench-byte-2.2.3/README +++ /dev/null @@ -1,66 +0,0 @@ -February 18, 2003 ------------------ -Bug-fix release. - -December 9, 1997 ----------------- -This release is based on beta release 2 of BYTE Magazine's BYTEmark -benchmark program (previously known as BYTE's Native Mode -Benchmarks). This document covers the Native Mode (a.k.a. Algorithm -Level) tests; benchmarks designed to expose the capabilities of a -system's CPU, FPU, and memory system. - -Running a "make" will create the binary if all goes well. It is called -"nbench" and performs a suite of 10 tests and compares the results to -a Dell Pentium 90 with 16 MB RAM and 256 KB L2 cache running MSDOS and -compiling with the Watcom 10.0 C/C++ compiler. If you define -DLINUX -during compilation (the default) then you also get a comparison to an -AMD K6/233 with 32 MB RAM and 512 KB L2-cache running Linux 2.0.32 and -using a binary which was compiled with GNU gcc version 2.7.2.3 and GNU -libc-5.4.38. - -For more verbose output specify -v as an argument. - -The primary web site is: http://www.tux.org/~mayer/linux/bmark.html - -The port to Linux/Unix was done by Uwe F. Mayer . - -The index-split was done by Andrew D. Balsa, and reflects the -realization that memory management is important in CPU design. The -original tests have been left alone, however, the tests NUMERIC SORT, -FP EMULATION, IDEA, and HUFFMAN now constitute the integer-arithmetic -focused benchmark index, while the tests STRING SORT, BITFIELD, and -ASSIGNMENT make up the new memory index. - -The algorithms were not changed from the source which was obtained -from the BYTE web site at http://www.byte.com/bmark/bmark.htm on -December 14, 1996. However, the source was modified to better work -with 64-bit machines (in particular the random number generator was -modified to always work with 32 bit, no matter what kind of hardware -you run it on). Furthermore, for some of the algorithms additional -resettings of the data was added to increase the consistency across -different hardware. Some extra debugging code was added, which has no -impact on normal runs. - -In case there is uneven system load due to other processes while this -benchmark suite executes, it might take longer to run than on an -unloaded system. This is because the benchmark does some statistical -analysis to make sure that the reported results are statistically -significant, and an increased variation in individual runs requires -more runs to achieve the required statistical confidence. - -This is a single-threaded benchmark and is not designed to measure the -performance gain on multi-processor machines. - -For details and customization read bdoc.txt. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/thirdparty/nbench-byte-2.2.3/README.motorola b/thirdparty/nbench-byte-2.2.3/README.motorola deleted file mode 100644 index 223001b22a3..00000000000 --- a/thirdparty/nbench-byte-2.2.3/README.motorola +++ /dev/null @@ -1,29 +0,0 @@ -The information in this file is old and no longer valid. It seems that -the GNU C library has caught up with Motorola's libmoto, and now -performance is just as good (or better) without libmoto. I'll include -the old notice out of historical reasons only. Currently libmoto is -available at ftp://ftp.mcg.mot.com/pub/SPS/PowerPC/software/mklinux/libmoto/, -but this is subject to change and not under my control. - -February 18, 2003 -Uwe F. Mayer - ---------------------------------------------------------------------------- - -If you have a Motorola CPU or equivalent: - -When linked with the 'libmoto' (floating point library from Motorola) -the results you obtain are much better. (FPU index of 0.896 versus -1.910 in one example.) - -The Motorola math library is currently available at: -http://www.mot.com/SPS/PowerPC/support/rsw_customer_support/mklinux/libmoto/libmoto_reg_mkdev.html - -If you have a Motorola CPU and you submit a result then please let me -know whether you used libmoto or not. Please read the file README.submit. - -I do not have a Motorola CPU, and I can't help you with installing the -library either. - -December 3, 1997 -Uwe F. Mayer \ No newline at end of file diff --git a/thirdparty/nbench-byte-2.2.3/README.nonlinux b/thirdparty/nbench-byte-2.2.3/README.nonlinux deleted file mode 100644 index 641fe0973d1..00000000000 --- a/thirdparty/nbench-byte-2.2.3/README.nonlinux +++ /dev/null @@ -1,50 +0,0 @@ -December 3, 1993 -================ - -DEC Unix 4.0 or DEC OSF1 and gcc --------------------------------- -Compiles cleanly if you don't use -funroll-loops with gcc-2.7.2.3 or earlier - -DEC UNIX 4.0 or DEC OSF1 and cc -------------------------------- -CC = cc -CFLAGS = -O3 -LINKFLAGS = -s -non_shared - -Compiles cleanly. - -SunOS and gcc -------------- -Compiles cleanly - -SunOS and cc ------------- -CC = cc -CFLAGS = -O3 -s - -Compiles with one warning during compilation of nbench1.c - -"/usr/ucbinclude/strings.h", line 48: warning: identifier redeclared: strlen - current : function() returning int - previous: function() returning uint : "/usr/include/string.h", line 98 - -HP-UX and gcc -------------- -Compiles with one warning during compilation of sysspec.c - -In file included from /usr/local/lib/gcc-lib/hppa1.1-hp-hpux9.05/2.7.2.1/include/malloc.h:9, - from sysspec.h:37, - from sysspec.c:37: -/usr/local/lib/gcc-lib/hppa1.1-hp-hpux9.05/2.7.2.1/include/sys/types.h:117: warning: empty declaration -/usr/local/lib/gcc-lib/hppa1.1-hp-hpux9.05/2.7.2.1/include/sys/types.h:118: warning: empty declaration - -DEC Ultrix and cc ------------------ -CC = cc -CFLAGS = -O2 -LINKFLAGS = -s - -Compiles with a warning about the correct usage of cut when running sysinfo.sh -cut: Usage: cut [-s] [-d] {-c | -f} file ... -cut: Usage: cut [-s] [-d] {-c | -f} file ... - diff --git a/thirdparty/nbench-byte-2.2.3/README.submit b/thirdparty/nbench-byte-2.2.3/README.submit deleted file mode 100644 index 0dd3138e934..00000000000 --- a/thirdparty/nbench-byte-2.2.3/README.submit +++ /dev/null @@ -1,33 +0,0 @@ -I plan on posting a digest of results in case people mail me any. -The URL will be linked to - -http://www.tux.org/~mayer/linux/bmark.html - -If you want to submit, then run the benchmark (use your own -compilation, I don't care with what flags or compiler, but I want all -numbers from a single benchmark run) and fill in the template as given -in the example below: - -CPU : AMD 5x86P75 (486DX4/133MHz) -L2 CACHE : 256 KB -OS : Linux 2.0.32 -C COMPILER : gcc 2.7.2.3 -LIBC : libc-5.4.38 -Pentium 90 INTEGER INDEX : 1.051 -Pentium 90 FLOATING-POINT INDEX : 0.450 -AMD K6/233 MEMORY INDEX : 0.337 -AMD K6/233 INTEGER INDEX : 0.238 -AMD K6/233 FLOATING-POINT INDEX : 0.230 - -Any other format is fine as long as it contains the same info (write -"unknown" or "?" for data you don't know). For example, you could just -cut the summary from the output of nbench and mail it together with -cache, CPU, and OS info in case it is not already present. Please do -not email me the complete output of nbench, or any other unnecessarily -long email, as this just eats up my hard-disk space. However, long -collections of results are of course welcome. - -Send your result to mayer@tux.org - -Uwe F. Mayer -February 18, 2003 diff --git a/thirdparty/nbench-byte-2.2.3/RESULTS b/thirdparty/nbench-byte-2.2.3/RESULTS deleted file mode 100644 index ccf233623d6..00000000000 --- a/thirdparty/nbench-byte-2.2.3/RESULTS +++ /dev/null @@ -1,138 +0,0 @@ -December 7, 1997 - -This file contains a few results so you may compare your machine. -If you read this much after December 1997 then the results herein -are probably obsolete. - -For a longer and hopefully more up-to-date list of results consult -http://www.tux.org/~mayer/linux/bmark.html -This web site, however, currently lists the old Pentium 90 indices! - -The indices below are with respect to the new AMD K6/233 baseline. - -OS : DEC Ultrix 4.4 -C compiler : cc -libc : unknown version -CPU : mips R6000 -L2 cache : ? -MEMORY INDEX : 0.029 -INTEGER INDEX : 0.046 -FLOATING-POINT INDEX: 0.077 - -OS : LINUX 2.0.31 -C compiler : gcc version 2.7.2.3 -libc : libc.so.5.4.38 -CPU : Intel 486DX2/66 MHz -L2 cache : 256 KB -MEMORY INDEX : 0.098 -INTEGER INDEX : 0.141 -FLOATING-POINT INDEX: 0.116 - -OS : LINUX 2.0.32 -C compiler : gcc version 2.7.2.3 -libc : libc.so.5.4.38 -CPU : AMD 5x86P75 (486DX4/133MHz) -L2 cache : 256 KB -MEMORY INDEX : 0.234 -INTEGER INDEX : 0.286 -FLOATING-POINT INDEX: 0.249 - -OS : OSF1 V3.2 214 -C compiler : cc -libc : unknown version -CPU : 21064 alpha (DEC 3000 MODEL 300, year 1993) -L2 cache : 256 KB -MEMORY INDEX : 0.358 -INTEGER INDEX : 0.362 -FLOATING-POINT INDEX: 0.656 - -OS : HP-UX A.09.05 -C compiler : gcc version 2.7.2.1 -libc : unknown version -CPU : 9000/715 -L2 cache : ? -MEMORY INDEX : 0.208 -INTEGER INDEX : 0.369 -FLOATING-POINT INDEX: 0.516 - -OS : LINUX 2.0.31 -C compiler : gcc version 2.7.2.3 -libc : libc.so.5.4.38 -CPU : Intel Pentium 133 MHz -L2 cache : 512 KB -MEMORY INDEX : 0.383 -INTEGER INDEX : 0.444 -FLOATING-POINT INDEX: 0.632 - -OS : SunOS 5.5.1 -C compiler : cc -libc : unknown version -CPU : SUN-Ultra-Enterprise-2 sparc -L2 cache : ? -MEMORY INDEX : 0.417 -INTEGER INDEX : 0.546 -FLOATING-POINT INDEX: 1.028 - -OS : LINUX 2.0.29 -C compiler : gcc version 2.7.2.3 -libc : libc.so.5.4.38 -CPU : Cyrix 6x86L PR200+ (at 2 x 75 = 150 MHz) -L2 cache : 256 KB -MEMORY INDEX : 0.666 -INTEGER INDEX : 0.599 -FLOATING-POINT INDEX: 0.508 - -OS : LINUX 2.0.31 -C compiler : gcc version 2.7.2.3 -libc : libc.so.5.4.38 -CPU : Intel Pentium MMX 200 MHz -L2 cache : 512 KB -MEMORY INDEX : 0.601 -INTEGER INDEX : 0.636 -FLOATING-POINT INDEX: 0.970 - -OS : LINUX 2.0.31 -C compiler : gcc version 2.7.2.3 -libc : libc.so.5.4.38 -CPU : Intel 686 PentiumPro 200 MHz -L2 cache : 256 KB (internal) -MEMORY INDEX : 0.699 -INTEGER INDEX : 0.732 -FLOATING-POINT INDEX: 1.140 - -OS : LINUX 2.0.29 -C compiler : gcc version 2.7.2.3 -libc : libc.so.5.4.38 -CPU : Cyrix 6x86MX PR233 (at 2.5 x 75 = 187.5 MHz) -L2 cache : 512 KB -MEMORY INDEX : 0.861 -INTEGER INDEX : 0.773 -FLOATING-POINT INDEX: 0.730 - -OS : LINUX 2.0.32 -C compiler : gcc version 2.7.2.3 -libc : libc.so.5.4.38 -CPU : AMD K6/233 -L2 cache : 512 KB -MEMORY INDEX : 1.000 -INTEGER INDEX : 1.000 -FLOATING-POINT INDEX: 1.000 - -OS : LINUX 2.0.31 -C compiler : gcc version 2.7.2.3 -libc : libc.so.5.4.38 -CPU : Intel 686 Pentium II 300 MHz -L2 cache : 512 KB -MEMORY INDEX : 1.255 -INTEGER INDEX : 1.093 -FLOATING-POINT INDEX: 1.842 - -OS : DEC UNIX 4.0b 564 -C compiler : cc -libc : unknown version -CPU : 21164 Alpha 300 MHz (dual CPU) -L2 cache : 96 KB -L3 cache : 4 MB per CPU -MEMORY INDEX : 0.973 -INTEGER INDEX : 1.124 -FLOATING-POINT INDEX: 3.237 diff --git a/thirdparty/nbench-byte-2.2.3/bdoc.txt b/thirdparty/nbench-byte-2.2.3/bdoc.txt deleted file mode 100644 index e557bb02dc3..00000000000 --- a/thirdparty/nbench-byte-2.2.3/bdoc.txt +++ /dev/null @@ -1,2109 +0,0 @@ -http://www.byte.com/bmark/bmark.htm ----------------------------------------------------------------------------- - -BYTEmark - ----------------------------------------------------------------------------- - -This is release 2 of BYTE Magazine's BYTEmark benchmark program (previously -known as BYTE's Native Mode Benchmarks). This document covers the Native -Mode (a.k.a. Algorithm Level) tests; benchmarks designed to expose the -capabilities of a system's CPU, FPU, and memory system. Another group of -benchmarks within the BYTEmark suite includes the Application Simulation -Benchmarks. They are detailed in a separate document. [NOTE: The -documentation for the Application simulation benchmarks should appear before -the end of March, 95. -- RG]. - -The Tests - -The Native Mode portion of the BYTEmark consists of a number of well-known -algorithms; some BYTE has used before in earlier versions of the benchmark, -others are new. The complete suite consists of 10 tests: - -Numeric sort - Sorts an array of 32-bit integers. - -String sort - Sorts an array of strings of arbitrary length. - -Bitfield - Executes a variety of bit manipulation functions. - -Emulated floating-point - A small software floating-point package. - -Fourier coefficients - A numerical analysis routine for calculating series -approximations of waveforms. - -Assignment algorithm - A well-known task allocation algorithm. - -Huffman compression - A well-known text and graphics compression algorithm. - -IDEA encryption - A relatively new block cipher algorithm. - -Neural Net - A small but functional back-propagation network simulator. - -LU Decomposition - A robust algorithm for solving linear equations. - -A more complete description of each test can be found in later sections of -this document. - -BYTE built the BYTEmark with the multiplatform world foremost in mind. There -were, of course, other considerations that we kept high on the list: - -Real-world algorithms. The algorithms should actually do something. Previous -benchmarks often moved gobs of bytes from one point to another, added or -subtracted piles and piles of numbers, or (in some cases) actually executed -NOP instructions. We should not belittle those tests of yesterday, they had -their place. However, we think it better that tests be based on activities -that are more complex in nature. - -Easy to port. All the benchmarks are written in "vanilla" ANSI C. This -provides us with the best chance of moving them quickly and accurately to -new processors and operating systems as they appear. It also simplifies -maintenance. - -This means that as new 64-bit (and, perhaps, 128-bit) processors appear, the -benchmarks can test them as soon as a compiler is available. - -Comprehensive. The algorithms were derived from a variety of sources. Some -are routines that BYTE had been using for some time. Others are routines -derived from well-known texts in the computer science world. Furthermore, -the algorithms differ in structure. Some simply "walk" sequentially through -one-dimensional arrays. Others build and manipulate two-dimensional arrays. -Finally, some benchmarks are "integer" tests, while others exercise the -floating-point coprocessor (if one is available). - -Scalable. We wanted these benchmarks to be useful across as wide a variety -of systems as possible. We also wanted to give them a lifetime beyond the -next wave of new processors. - -To that end, we incorporated "dynamic workload adjustment." A complete -description of this appears in a later section. In a nutshell, this allows -the tests to "expand or contract" depending on the capabilities of the -system under test, all the while providing consistent results so that fair -and accurate comparisons are possible. - -Honesty In Advertising - -We'd be lying if we said that the BYTEmark was all the benchmarking that -anyone would ever need to run on a system. It would be equally inaccurate to -suggest that the tests are completely free of inadequacies. There are many -things the tests do not do, there are shortcomings, and there are problems. - -BYTE will continue to improve the BYTEmark. The source code is freely -available, and we encourage vendors and users to examine the routines and -provide us with their feedback. In this way, we assure fairness, -comprehensiveness, and accuracy. - -Still, as we mentioned, there are some shortcomings. Here are those we -consider the most significant. Keep them in mind as you examine the results -of the benchmarks now and in the future. - -At the mercy of C compilers. Being written in ANSI C, the benchmark program -is highly portable. This is a reflection of the "world we live in." If this -were a one-processor world, we might stand a chance at hand-crafting a -benchmark in assembly language. (At one time, that's exactly what BYTE did.) -Not today, no way. - -The upshot is that the benchmarks must be compiled. For broadest coverage, -we selected ANSI C. And when they're compiled, the resulting executable's -performance can be highly dependent on the capabilities of the C compiler. -Today's benchmark results can be blown out of the water tomorrow if someone -new enters the scene with an optimizing strategy that outperforms existing -competition. - -This concern is not easily waved off. It will require you to keep careful -track of compiler version and optimization switches. As BYTE builds its -database of benchmark results, version number and switch setting will become -an integral part of that data. This will be true for published information -as well, so that you can make comparisons fairly and accurately. BYTE will -control the distribution of test results so that all relevant compiler -information is attached to the data. - -As a faint justification -- for those who think this situation results in -"polluted" tests -- we should point out that we are in the same boat as all -the other developers (at least, all those using C compilers -- and that's -quite a sizeable group). If the only C compilers for a given system happen -to be poor ones, everyone suffers. It's a fact that a given platform's -ultimate potential depends as much on the development software available as -on the technical achievements of the hardware design. - -It's just CPU and FPU. It's very tempting to try to capture the performance -of a machine in a single number. That has never been possible -- though it's -been tried a lot -- and the gap between that ideal and reality will forever -widen. - -These benchmarks are meant to expose the theoretical upper limit of the CPU, -FPU, and memory architecture of a system. They cannot measure video, disk, -or network throughput (those are the domains of a different set of -benchmarks). You should, therefore, use the results of these tests as part, -not all, of any evaluation of a system. - -Single threaded. Currently, each benchmark test uses only a single execution -thread. It's unlikely that you'll find any modern operating system that does -not have some multitasking component. How a system "scales" as more tasks -are run simultaneously is an effect that the current benchmarks cannot -explore. - -BYTE is working on a future version of the tests that will solve this -problem. - -The tests are synthetic. This quite reasonable argument is based on the fact -that people don't run benchmarks for a living, they run applications. -Consequently, the only true measure of a system is how well it performs -whatever applications you will be running. This, in fact, is the philosophy -behind the BAPCo benchmarks. - -This is not a point with which we would disagree. BYTE regularly makes use -of a variety of application benchmarks. None of this suggests, however, that -the BYTEmark benchmarks serve no purpose. - -BYTEmark's results should be used as predictors. They can be moved to a new -platform long before native applications will be ported. The BYTEmark -benchmarks will therefore provide an early look at the potential of the -machine. Additionally, the BYTEmark permits you to "home in" on an aspect of -the overall architecture. How well does the system perform when executing -floating-point computations? Does its memory architecture help or hinder the -management of memory buffers that may fall on arbitrary address boundaries? -How does the cache work with a program whose memory access favors moving -randomly through memory as opposed to moving sequentially through memory? - -The answers to these questions can give you a good idea of how well a system -would support a particular class of applications. Only a synthetic benchmark -can give the narrow view necessary to find the answers. - -Dynamic Workloads - -Our long history of benchmarking has taught us one thing above all others: -Tomorrow's system will go faster than today's by an amount exceeding your -wildest guess -- and then some. Dealing with this can become an unending -race. - -It goes like this: You design a benchmark algorithm, you specify its -parameters (how big the array is, how many loops, etc.), you run it on -today's latest super-microcomputer, collect your data, and go home. A new -machine arrives the next day, you run your benchmark, and discover that the -test executes so quickly that the resolution of the clock routine you're -using can't keep up with it (i.e., the test is over and done before the -system clock even has a chance to tick). - -If you modify your routine, the figures you collected yesterday are no good. -If you create a better clock routine by sneaking down into the system -hardware, you can kiss portability goodbye. - -The BYTEmark benchmarks solve this problem by a process we'll refer to as -"dynamic workload adjustment." In principle, it simply means that if the -test runs so fast that the system clock can't time it, the benchmark -increases the test workload -- and keeps increasing it -- until enough time -is consumed to gather reliable test results. - -Here's an example. - -The BYTEmark benchmarks perform timing using a "stopwatch" paradigm. The -routine StartStopwatch() begins timing; StopStopwatch() ends timing and -reports the elapsed time in clock ticks. Now, "clock ticks" is a value that -varies from system to system. We'll presume that our test system provides -1000 clock ticks per second. (We'll also presume that the system actually -updates its clock 1000 times per second. Surprisingly, some systems don't do -that. One we know of will tell you that the clock provides 100 ticks per -second, but updates the clock in 5- or 6-tick increments. The resolution is -no better than somewhere around 1/18th of a second.) Here, when we say -"system" we mean not only the computer system, but the environment provided -by the C compiler. Interestingly, different C compilers for the same system -will report different clock ticks per second. - -Built into the benchmarks is a global variable called GLOBALMINTICKS. This -variable is the minimum number of clock ticks that the benchmark will allow -StopStopwatch() to report. - -Suppose you run the Numeric Sort benchmark. The benchmark program will -construct an array filled with random numbers, call StartStopwatch(), sort -the array, and call StopStopwatch(). If the time reported in StopStopwatch() -is less than GLOBALMINTICKS, then the benchmark will build two arrays, and -try again. If sorting two arrays took less time than GLOBALMINTICKS, the -process repeats with more arrays. - -This goes on until the benchmark makes enough work so that an interval -between StartStopwatch() and StopStopwatch() exceeds GLOBALMINTICKS. Once -that happens, the test is actually run, and scores are calculated. - -Notice that the benchmark didn't make bigger arrays, it made more arrays. -That's because the time taken by the sort test does not increase linearly as -the array grows, it increases by a factor of N*log(N) (where N is the size -of the array). - -This principle is applied to all the benchmark tests. A machine with a less -accurate clock may be forced to sort more arrays at a time, but the results -are given in arrays per second. In this way fast machines, slow machines, -machines with accurate clocks, machines with less accurate clocks, can all -be tested with the same code. - -Confidence Intervals - -Another built-in feature of the BYTEmark is a set of statistical-analysis -routines. Running benchmarks is one thing; the question arises as to how -many times should a test be run until you know you have a good sampling. -Also, can you determine whether the test is stable (i.e., do results vary -widely from one execution of the benchmark to the next)? - -The BYTEmark keeps score as follows: Each test (a test being a numeric -sort, a string sort, etc.) is run five times. These five scores are -averaged, the standard deviation is determined, and a 95% confidence -half-interval for the mean is calculated (using the student t -distribution). This tells us that the true average lies -- with a 95% -probability -- within plus or minus the confidence half-interval of -the calculated average. If this half-interval is within 5% of the -calculated average, the benchmarking stops. Otherwise, a new test is -run and the calculations are repeated with all of the runs done so -far, including the new one. The benchmark proceeds this way up to a -total of 30 runs. If the length of the half-interval is still bigger -than 5% of the calculated average then a warning issued that the -results might not be statistically certain before the average is -displayed. - -** Fixed a statistical bug here. Uwe F. Mayer - -The upshot is that, for each benchmark test, the true average is -- with a -95% level of confidence -- within 5% of the average reported. Here, the -"true average" is the average we would get were we able to run the tests -over and over again an infinite number of times. - -This specification ensures that the calculation of results is controlled; -that someone running the tests in California will use the same technique for -determining benchmark results as someone running the tests in New York. - -In case there is uneven system load due to other processes while this -benchmark suite executes, it might take longer to run the benchmark suite -as compared to a run an unloaded system. This is because the benchmark does -some statistical analysis to make sure that the reported results are -statistically significant (as explained above), and a high variation in -individual runs requires more runs to achieve the required statistical -confidence. - -*** added last the paragraph, Uwe F. Mayer - -Interpreting Results - -Of course, running the benchmarks can present you with a boatload of data. -It can get mystifying, and some of the more esoteric statistical information -is valuable only to a limited audience. The big question is: What does it -all mean? - -First, we should point out that the BYTEmark reports both "raw" and indexed -scores for each test. The raw score for a particular test amounts to the -"iterations per second" of that test. For example, the numeric sort test -reports as its raw score the number of arrays it was able to sort per -second. - -The indexed score is the raw score of the system under test divided by the -raw score obtained on the baseline machine. As of this release, the -baseline machine is a DELL 90 Mhz Pentium XPS/90 with 16 MB of RAM and 256K -of external processor cache. (The compiler used was the Watcom C/C++ 10.0 -compiler; optimizations set to "fastest possible code", 4-byte structure -alignment, Pentium code generation with Pentium register-based calling. The -operating system was MSDOS.) The indexed score serves to "normalize" the -raw scores, reducing their dynamic range and making them easier to -grasp. Simply put, if your machine has an index score of 2.0 on the numeric -sort test, it performed that test twice as fast as this 90 Mhz Pentium. - -If you run all the tests (as you'll see, it is possible to perform "custom -runs", which execute only a subset of the tests) the BYTEmark will also -produce two overall index figures: Integer index and Floating-point index. -The Integer index is the geometric mean of those tests that involve only -integer processing -- numeric sort, string sort, bitfield, emulated -floating-point, assignment, Huffman, and IDEA -- while the Floating-point -index is the geometric mean of those tests that require the floating-point -coprocessor -- Fourier, neural net, and LU decomposition. You can use these -scores to get a general feel for the performance of the machine under test -as compared to the baseline 90 Mhz Pentium. - -The Linux/Unix port has a second baseline machine, it is an AMD K6/233 with -32 MB RAM and 512 KB L2-cache running Linux 2.0.32 and using GNU gcc -version 2.7.2.3 and libc-5.4.38. The integer index was split as suggested -by Andrew D. Balsa , and reflects the realization that -memory management is important in CPU design. The original tests have been -left alone, however, the geometric mean of the tests NUMERIC SORT, FP -EMULATION, IDEA, and HUFFMAN now constitutes the integer-arithmetic focused -benchmark index, while the geometric mean of the tests STRING SORT, -BITFIELD, and ASSIGNMENT makes up the new memory index. The floating point -index has been left alone, it is still the geometric mean of FOURIER, -NEURAL NET, and LU DECOMPOSITION. - -*** added the section on Linux, Uwe F. Mayer - -What follows is a list of the benchmarks and associated brief remarks that -describe what the tests do: What they exercise; what a "good" result or a -"bad" result means. Keep in mind that, in this expanding universe of faster -processors, bigger caches, more elaborate memory architectures, "good" and -"bad" are indeed relative terms. A good score on today's hot new processor -will be a bad score on tomorrow's hot new processor. - -These remarks are based on empirical data and profiling that we have done to -date. (NOTE: The profiling is limited to Intel and Motorola 68K on this -release. As more data is gathered, we will be refining this section. -3/14/95--RG) - -Benchmark Description - -Numeric sort Generic integer performance. Should - exercise non-sequential performance - of cache (or memory if cache is less - than 8K). Moves 32-bit longs at a - time, so 16-bit processors will be - at a disadvantage. - - - -String sort Tests memory-move performance. - Should exercise non-sequential - performance of cache, with added - burden that moves are byte-wide and - can occur on odd address boundaries. - May tax the performance of - cell-based processors that must - perform additional shift operations - to deal with bytes. - - - -Bitfield Exercises "bit twiddling" - performance. Travels through memory - in a somewhat sequential fashion; - different from sorts in that data is - merely altered in place. If - properly compiled, takes into - account 64-bit processors, which - should see a boost. - - - -Emulated F.P. Past experience has shown this test - to be a good measurement of overall - performance. - - - -Fourier Good measure of transcendental and - trigonometric performance of FPU. - Little array activity, so this test - should not be dependent of cache or - memory architecture. - - - -Assignment The test moves through large integer - arrays in both row-wise and - column-wise fashion. Cache/memory - with good sequential performance - should see a boost (memory is - altered in place -- no moving as in - a sort operation). Processing is - done in 32-bit chunks -- no - advantage given to 64-bit - processors. - - - -Huffman A combination of byte operations, - bit twiddling, and overall integer - manipulation. Should be a good - general measurement. - - - -IDEA Moves through data sequentially in - 16-bit chunks. Should provide a - good indication of raw speed. - - - -Neural Net Small-array floating-point test - heavily dependent on the exponential - function; less dependent on overall - FPU performance. Small arrays, so - cache/memory architecture should not - come into play. - - - -LU decomposition. A floating-point test that moves - through arrays in both row-wise and - column-wise fashion. Exercises only - fundamental math operations (+, -, - *, /). - -The Command File - -Purpose - -The BYTEmark program allows you to override many of its default parameters -using a command file. The command file also lets you request statistical -information, as well as specify an output file to hold the test results for -later use. - -You identify the command file using a command-line argument. E.G., - -C:NBENCH -cCOMFILE.DAT - -tells the benchmark program to read from COMFILE.DAT in the current -directory. - -The content of the command file is simply a series of parameter names and -values, each on a single line. The parameters control internal variables -that are either global in nature (i.e., they effect all tests in the -program) or are specific to a given benchmark test. - -The parameters are listed in a reference guide that follows, arranged in the -following groups: - -Global Parameters - -Numeric Sort - -String Sort - -Bitfield - -Emulated floating-point - -Fourier coefficients - -Assignment algorithm - -IDEA encryption - -Huffman compression - -Neural net - -LU decomposition - -As mentioned above, those items listed under "Global Parameters" affect all -tests; the rest deal with specific benchmarks. There is no required ordering -to parameters as they appear in the command file. You can specify them in -any sequence you wish. - -You should be judicious in your use of a command file. Some parameters will -override the "dynamic workload" adjustment that each test performs. Doing -this completely bypasses the benchmark code that is designed to produce an -accurate reading from your system clock. Other parameters will alter default -settings, yielding test results that cannot be compared with published -benchmark results. - -A Sample Command File - -Suppose you built a command file that contained the following: - -ALLSTATS=T - -CUSTOMRUN=T - -OUTFILE=D:\DATA.DAT - -DONUMSORT=T - -DOLU=T - -Here's what this file tells the benchmark program: - -ALLSTATS=T means that you've requested a "dump" of all the statistics the -test gathers. This includes not only the standard deviations of tests run, -it also produces test-specific information such as the number of arrays -built, the array size, etc. - -CUSTOMRUN=T tells the system that this is a custom run. Only tests -explicitly specified will be executed. - -OUTFILE=D:\DATA.DAT will write the output of the benchmark to the file -DATA.DAT on the root of the D: drive. (If DATA.DAT already exists, output -will be appended to the file.) - -DONUMSORT=T tells the system to run the numeric sort benchmark. (This was -necessary on account of the CUSTOMRUN=T line, above.) - -DOLU=T tells the system to run the LU decomposition benchmark. - -Command File Parameters Reference - -(NOTE: Altering some global parameters can invalidate results for comparison -purposes. Those parameters are indicated in the following section by a bold -asterisk (*). If you alter any parameters so indicated, you may NOT publish -the resulting data as BYTEmark scores.) - -Global Parameters - -GLOBALMINTICKS= - -This overrides the default global_min_ticks value (defined in NBENCH1.H). -The global_min_ticks value is defined as the minimum number of clock ticks -per iteration of a particular benchmark. For example, if global_min_ticks is -set to 100 and the numeric sort benchmark is run; each iteration MUST take -at least 100 ticks, or the system will expand the work-per-iteration. - -MINSECONDS= - -Sets the minimum number of seconds any particular test will run. This has -the effect of controlling the number of repetitions done. Default: 5. - -ALLSTATS= - -Set this flag to T for a "dump" of all statistics. The information displayed -varies from test to test. Default: F. - -OUTFILE= - -Specifies that output should go to the specified output file. Any test -results and statistical data displayed on-screen will also be written to the -file. If the file does not exist, it will be created; otherwise, new output -will be appended to an existing file. This allows you to "capture" several -runs into a single file for later review. - -Note: the path should not appear in quotes. For example, something like the -following would work: OUTFILE=C:\BENCH\DUMP.DAT - -CUSTOMRUN= - -Set this flag to T for a custom run. A "custom run" means that the program -will run only the benchmark tests that you explicitly specify. So, use this -flag to run a subset of the tests. Default: F. - -Numeric Sort - -DONUMSORT= - -Indicates whether to do the numeric sort. Default is T, unless this is a -custom run (CUSTOMRUN=T), in which case default is F. - -NUMNUMARRAYS= - -Indicates the number of numeric arrays the system will build. Setting this -value will override the program's "dynamic workload" adjustment for this -test.* - -NUMARRAYSIZE= - -Indicates the number of elements in each numeric array. Default is 8001 -entries. (NOTE: Altering this value will invalidate the test for comparison -purposes. The performance of the numeric sort test is not related to the -array size as a linear function; i.e., an array twice as big will not take -twice as long. The relationship involves a logarithmic function.)* - -NUMMINSECONDS= - -Overrides MINSECONDS for the numeric sort test. - -String Sort - -DOSTRINGSORT= - -Indicates whether to do the string sort. Default is T, unless this is a -custom run (CUSTOMRUN=T), in which case the default is F. - -STRARRAYSIZE= - -Sets the size of the string array. Default is 8111. (NOTE: Altering this -value will invalidate the test for comparison purposes. The performance of -the string sort test is not related to the array size as a linear function; -i.e., an array twice as big will not take twice as long. The relationship -involves a logarithmic function.)* - -NUMSTRARRAYS= - -Sets the number of string arrays that will be created to run the test. -Setting this value will override the program's "dynamic workload" adjustment -for this test.* - -STRMINSECONDS= - -Overrides MINSECONDS for the string sort test. - -Bitfield - -DOBITFIELD= - -Indicates whether to do the bitfield test. Default is T, unless this is a -custom run (CUSTOMRUN=T), in which case the default is F. - -NUMBITOPS= - -Sets the number of bitfield operations that will be performed. Setting this -value will override the program's "dynamic workload" adjustment for this -test.* - -BITFIELDSIZE= - -Sets the number of 32-bit elements in the bitfield arrays. The default value -is dependent on the size of a long as defined by the current compiler. For a -typical compiler that defines a long to be 32 bits, the default is 32768. -(NOTE: Altering this parameter will invalidate test results for comparison -purposes.)* - -BITMINSECONDS= - -Overrides MINSECONDS for the bitfield test. - -Emulated floating-point - -DOEMF= - -Indicates whether to do the emulated floating-point test. Default is T, -unless this is a custom run (CUSTOMRUN=T), in which case the default is F. - -EMFARRAYSIZE= - -Sets the size (number of elements) of the emulated floating-point benchmark. -Default is 3000. The test builds three arrays, each of equal size. This -parameter sets the number of elements for EACH array. (NOTE: Altering this -parameter will invalidate test results for comparison purposes.)* - -EMFLOOPS= - -Sets the number of loops per iteration of the floating-point test. Setting -this value will override the program's "dynamic workload" adjustment for -this test.* - -EMFMINSECONDS= - -Overrides MINSECONDS for the emulated floating-point test. - -Fourier coefficients - -DOFOUR= - -Indicates whether to do the Fourier test. Default is T, unless this is a -custom run (CUSTOMRUN=T), in which case the default is F. - -FOURASIZE= - -Sets the size of the array for the Fourier test. This sets the number of -coefficients the test will derive. NOTE: Specifying this value will override -the system's "dynamic workload" adjustment for this test, and may make the -results invalid for comparison purposes.* - -FOURMINSECONDS= - -Overrides MINSECONDS for the Fourier test. - -Assignment Algorithm - -DOASSIGN= - -Indicates whether to do the assignment algorithm test. Default is T, unless -this is a custom run (CUSTOMRUN=T), in which case the default is F. - -ASSIGNARRAYS= - -Indicates the number of arrays that will be built for the test. Specifying -this value will override the system's "dynamic workload" adjustment for this -test. (NOTE: The size of the arrays in the assignment algorithm is fixed at -101 x 101. Altering the array size requires adjusting global constants and -recompiling; to do so, however, would invalidate test results.)* - -ASSIGNMINSECONDS= - -Overrides MINSECONDS for the assignment algorithm test. - -IDEA encryption - -DOIDEA= - -Indicates whether to do the IDEA encryption test. Default is T, unless this -is a custom run (CUSTOMRUN=T), in which case the default is F. - -IDEAARRAYSIZE= - -Sets the size of the plain-text character array that will be encrypted by the -test. Default is 4000. The benchmark actually builds 3 arrays: 1st -plain-text, encrypted version, and 2nd plain-text. The 2nd plain-text array is -the destination for the decryption process [part of the test]. All arrays -are set to the same size. (NOTE: Specifying this value will invalidate test -results for comparison purposes.)* - -IDEALOOPS= - -Indicates the number of loops in the IDEA test. Specifying this value will -override the system's "dynamic workload" adjustment for this test.* - -IDEAMINSECONDS= - -Overrides MINSECONDS for the IDEA test. - -Huffman compression - -DOHUFF= - -Indicates whether to do the Huffman test. Default is T, unless this is a -custom run (CUSTOMRUN=T), in which case the default is F. - -HUFFARRAYSIZE= - -Sets the size of the string buffer that will be compressed using the Huffman -test. The default is 5000. (NOTE: Altering this value will invalidate test -results for comparison purposes.)* - -HUFFLOOPS= - -Sets the number of loops in the Huffman test. Specifying this value will -override the system's "dynamic workload" adjustment for this test.* - -HUFFMINSECONDS= - -Overrides MINSECONDS for the Huffman test. - -Neural net - -DONNET= - -Indicates whether to do the Neural Net test. Default is T, unless this is a -custom run (CUSTOMRUN=T), in which case the default is F. - -NNETLOOPS= - -Sets the number of loops in the Neural Net test. NOTE: Altering this value -overrides the benchmark's "dynamic workload" adjustment algorithm, and may -invalidate the results for comparison purposes.* - -NNETMINSECONDS= - -Overrides MINSECONDS for the Neural Net test. - -LU decomposition - -DOLU= - -Indicates whether to do the LU decomposition test. Default is T, unless this -is a custom run (CUSTOMRUN=T), in which case the default is F. - -LUNUMARRAYS= - -Sets the number of arrays in each iteration of the LU decomposition test. -Specifying this value will override the system's "dynamic workload" -adjustment for this test.* - -LUMINSECONDS= - -Overrides MINSECONDS for the LU decomposition test. - -Numeric Sort - -Description - -This benchmark is designed to explore how well the system sorts a numeric -array. In this case, a numeric array is a one-dimensional collection of -signed, 32-bit integers. The actual sorting is performed by a heapsort -algorithm (see the text box following for a description of the heapsort -algorithm). - -It's probably unnecessary to point out (but we'll do it anyway) that sorting -is a fundamental operation in computer application software. You'll likely -find sorting routines nestled deep inside a variety of applications; -everything from database systems to operating-systems kernels. - -The numeric sort benchmark reports the number of arrays it was able to sort -per second. The array size is set by a global constant (it can be overridden -by the command file -- see below). - -Analysis - -Optimized 486 code: Profiling of the numeric sort benchmark using Watcom's -profiler (Watcom C/C++ 10.0) indicates that the algorithm spends most of its -time in the numsift() function (specifically, about 90% of the benchmark's -time takes place in numsift()). Within numsift(), two if statements dominate -time spent: - -if(array[k] can be used to change this value, but results produced by -doing this will make your results incompatible with other runs of the -benchmark (since results will be skewed -- see preceding paragraph). - -To test for a correct execution of the numeric sort benchmark, #define the -DEBUG symbol. This will enable code that verifies that arrays are properly -sorted. You should run the benchmark program using a command file that has -only the numeric sort test enabled. If there is an error, the program will -display "SORT ERROR" (If this happens, it's possible that tons of "SORT -ERROR" messages will be emitted, so it's best not to redirect output to a -file), otherwise it will print "Numeric sort: OK" (also quite a few times). - -References - -Gonnet, G.H. 1984, Handbook of Algorithms and Data Structures (Reading, MA: -Addison-Wesley). - -Knuth, Donald E. 1968, Fundamental Algorithms, vol 1 of The Art of Computer -Programming (Reading, MA: Addison-Wesley). - -Press, William H., Flannery, Brian P., Teukolsky, Saul A., and Vetterling, -William T. 1989, Numerical Recipes in Pascal (Cambridge: Cambridge -University Press). - -Heapsort - -The heapsort algorithm is well-covered in a number of the popular -computer-science textbooks. In fact, it gets a pat on the back in Numerical -Recipes (Press et. al.), where the authors write: - -Heapsort is our favorite sorting routine. It can be recommended -wholeheartedly for a variety of sorting applications. It is a true -"in-place" sort, requiring no auxiliary storage. - -Heapsort works by building the array into a kind of a queue called a heap. -You can imagine this heap as being a form of in-memory binary tree. The -topmost (root) element of the tree is the element that -- were the array -sorted -- would be the largest element in the array. Sorting takes place by -first constructing the heap, then pulling the root off the tree, promoting -the next largest element to the root, pulling it off, and so on. (The -promotion process is known as "sifting up.") - -Heapsort executes in N log2 N time even in its worst case. Unlike some other -sorting algorithms, it does not benefit from a partially sorted array -(though Gonnet does refer to a variation of heapsort, called "smoothsort," -which does -- see references). - -String Sort - -Description - -This benchmark is designed to gauge how well the system moves bytes around. -By that we mean, how well the system can copy a string of bytes from one -location to another; source and destination being aligned to arbitrary -addresses. (This is unlike the numeric sort array, which moves bytes -longword-at-a-time.) The strings themselves are built so as to be of random -length, ranging from no fewer than 4 bytes and no greater than 80 bytes. The -mixture of random lengths means that processors will be forced to deal with -strings that begin and end on arbitrary address boundaries. - -The string sort benchmark uses the heapsort algorithm; this is the same -algorithm as is used in the numeric sort benchmark (see the sidebar on the -heapsort for a detailed description of the algorithm). - -Manipulation of the strings is actually handled by two arrays. One array -holds the strings themselves; the other is a pointers array. Each member of -the pointers array carries an offset that points into the string array, so -that the ith pointer carries the offset to the ith string. This allows the -benchmark to rapidly locate the position of the ith string. (The sorting -algorithm requires exchanges of items that might be "distant" from one -another in the array. It's critical that the routine be able to rapidly find -a string based on its indexed position in the array.) - -The string sort benchmark reports the number of string arrays it was able to -sort per second. The size of the array is set by a global constant. - -Analysis - -Optimized 486 code (Watcom C/C++ 10.0): Profiling of the string sort -benchmark indicates that it spends most of its time in the C library routine -memmove(). Within that routine, most of the execution is consumed by a pair -of instructions: rep movsw and rep movsd. These are repeated string move -- -word width and repeated string move -- doubleword width, respectively. - -This is precisely where we want to see the time spent. It's interesting to -note that the memmove() of the particular compiler/profiler tested (Watcom -C/C++ 10.0) was "smart" enough to do most of the moving on word or -doubleword boundaries. The string sort benchmark specifically sets arbitrary -boundaries, so we'd expect to see lots of byte-wide moves. The "smart" -memmove() is able to move bytes only when it has to, and does the remainder -of the work via words and doublewords (which can move more bits at a time). - -680x0 Code (Macintosh CodeWarrior): Because CodeWarrior's profiler is -function based, it is impossible to get an idea of how much time the test -spends in library routines such as memmove(). Fortunately, as an artifact of -the early version of the benchmark, the string sort algorithm makes use of -the MoveMemory() routine in the sysspec.c file (system specific routines). -This call, on anything other than a 16-bit DOS system, calls memmove() -directly. Hence, we can get a good approximation of how much time is spent -moving bytes. - -The answer is that nearly 78% of the benchmark's time is consumed by -MoveMemory(), the rest being taken up by the other routines (the -str_is_less() routine, which performs string comparisons, takes about 7% of -the time). As above, we can guess that most of the benchmark's time is -dependent on the performance of the library's memmove() routine. - -Porting Considerations - -As with the numeric sort routine, the string sort benchmark should be simple -to port. Simpler, in fact. The string sort benchmark routine is not -dependent on any typedef that may change from machine to machine (unless a -char type is not 8 bits). - -The string sort benchmark depends on the following global definitions: - -NUMSTRARRAYS - Sets the upper limit on the number of arrays that the -benchmark will attempt to build. The string sort benchmark creates work for -itself by requiring the system to sort more and more arrays, not bigger and -bigger arrays. (See section on Numeric Sort for an explanation.) This -constant sets the upper limit to the number of arrays the system will build -before it signals an error. The default value is 100, and may be changed if -your system exceeds this limit. - -STRARRAYSIZE - Sets the default size of the string arrays built. We say -"arrays" because, as with the numeric sort benchmark, the system adds work -not by expanding the size of the array, but by adding more arrays. This -value is set to 8111, and should not be modified, since results would not be -comparable with other runs of the same benchmark on other machines. - -To test for a correct execution of the string sort benchmark, #define -the DEBUG symbol. This will enable code that verifies the arrays are -properly sorted. Set up a command file that runs only the string sort, -and execute the benchmark program. If the routine is operating -properly, the benchmark will print "String sort: OK", this message is -printed quite often. Otherwise, the program will display "SORT ERROR" -for each pair of strings it finds out of order (which can be really -often). - -References - -See the references for the Numeric Sort benchmark. - -Bitfield Operations - -Description - -The purpose of this benchmark is to explore how efficiently the system -executes operations that deal with "twiddling bits." The test is set up to -simulate a "bit map"; a data structure used to keep track of storage usage. -(Don't confuse this meaning of "bitmap" with its use in describing a -graphics data structure.) - -Systems often use bit maps to keep an inventory of memory blocks or (more -frequently) disk blocks. In the case of a bit map that manages disk usage, -an operating system will set aside a buffer in memory so that each bit in -that buffer corresponds to a block on the disk drive. A 0 bit means that the -corresponding block is free; a 1 bit means the block is in use. Whenever a -file requests a new block of disk storage, the operating system searches the -bit map for the first 0 bit, sets the bit (to indicate that the block is now -spoken for), and returns the number of the corresponding disk block to the -requesting file. - -These types of operations are precisely what this test simulates. A block of -memory is set allocated for the bit map. Another block of memory is -allocated, and set up to hold a series of "bit map commands". Each bitmap -command tells the simulation to do 1 of 3 things: - -1) Clear a series of consecutive bits, - -2) Set a series of consecutive bits, or - -3) Complement (1->0 and 0->1) a series of consecutive bits. - -The bit map command block is loaded with a set of random bit map commands -(each command covers an random number of bits), and simulation routine steps -sequentially through the command block, grabbing a command and executing it. - -The bitfield benchmark reports the number of bits it was able to operate on -per second. The size of the bit map is constant; the bitfield operations -array is adjusted based on the capabilities of the processor. (See the -section describing the auto-adjust feature of the benchmarks.) - -Analysis - -Optimized 486 code: Using the Watcom C/C++ 10.0 profiler, the Bitfield -benchmark appears to spend all of its time in two routines: ToggleBitRun() -(74% of the time) and DoBitFieldIteration() (24% of the time). We say -"appears" because this is misleading, as we will explain. - -First, it is important to recall that the test performs one of three -operations for each run of bits (see above). The routine ToggleBitRun() -handles two of those three operations: setting a run of bits and clearing a -run of bits. An if() statement inside ToggleBitRun() decides which of the -two operations is performed. (Speed freaks will quite rightly point out that -this slows the entire algorithm. ToggleBitRun() is called by a switch() -statement which has already decided whether bits should be set or cleared; -it's a waste of time to have ToggleBitRun() have to make that decision yet -again.) - -DoBitFieldIteration() is the "outer" routine that calls ToggleBitRun(). -DoBitFieldIteration() also calls FlipBitRun(). This latter routine is the -one that performs the third bitfield operation: complementing a run of bits. -FlipBitRun() gets no "air time" at all (while DoBitFieldIteration() gets 24 -% of the time) simply because the compiler's optimizer recognizes that -FlipBitRun() is only called by DoBitFieldIteration(), and is called only -once. Consequently, the optimizer moves FlipBitRun() "inline", i.e., into -DoBitFieldIteration(). This removes an unnecessary call/return cycle (and is -probably part of the reason why the FlipBitRun() code gets 24% of the -algorithm's time, instead of something closer to 30% of its time.) - -Within the routines, those lines of code that actually do the shifting, the -and operations, and the or operations, consume time evenly. This should make -for a good test of a processor's "bit twiddling" capabilities. - -680x0 Code (Macintosh CodeWarrior): The CodeWarrior profiler is function -based. Consequently, it is impossible to produce a profile of machine -instruction execution time. We can, however, get a good picture of how the -algorithm divides its time among the various functions. - -Unlike the 486 compiler, the CodeWarrior compiler did not appear to collapse -the FlipBitRun() routine into the outer DoBitFieldIteration() routine. (We -don't know this for certain, of course. It's possible that the compiler -would have done this had we not been profiling.) - -In any case, the time spent in the two "core" routines of the bitfield test -are shown below: - -FlipBitRun() - 18031.2 microsecs (called 509 times) - -ToggleBitRun() - 50770.6 microsecs (called 1031 times) - -In terms of total time, FlipBitRun() takes about 35% of the time (it gets -about 33% of the calls). Remember, ToggleBitRun() is a single routine that -is called both to set and clear bits. Hence, ToggleBitRun() is called twice -as often as FlipBitRun(). - -We can conclude that time spent setting bits to 1, setting bits to 0, and -changing the state of bits, is about equal; the load is balanced close to -what we'd expect it to be, based on the structure of the algorithm. - -Porting Considerations - -The bitfield operations benchmark is dependent on the size of the long -datatype. On most systems, this is 32 bits. However, on some of the newer -RISC chips, a long can be 64 bits long. If your system does use 64-bit -longs, you'll need to #define the symbol LONG64. - -If you are unsure of the size of a long in your system (some C compiler -manuals make it difficult to discover), simply place an ALLSTATS=T line in -the command file and run the benchmarks. This will cause the benchmark -program to display (among other things) the size of the data types int, -short, and long in bytes. - -BITFARRAYSIZE - Sets the number of longs in the bit map array. This number -is fixed, and should not be altered. The bitfield test adjusts itself by -adding more bitfield commands (see above), not by creating a larger bit map. - -Currently, there is no code added to test for correct execution. If you are -concerned that your port was incorrect, you'll need to step through your -favorite debugger and verify execution against the original source code. - -** I added a resetting of the random number generator, and a resetting -** of the bitfield to each loop. Those operations are outside of the -** timed loop, and should add to make the benchmark more consistent. -** There also is now debugging information available. If you define -** DEBUG then the program will write a file named "debugbit.dat", -** which is the contents of the bitfield after the calibration loop of -** 30 operations. You can compare this file with the file -** "debugbit.good" that comes with the distribution. -** Uwe F. Mayer - -References - -None. - -Emulated Floating-point - -Description - -The emulated floating-point benchmark includes routines that are similar to -those that would be executed whenever a system performs floating-point -operations in the absence of a coprocessor. In general, this amounts to a -mixture of integer instructions, including shift operations, integer -addition and subtraction, and bit testing (among others). - -The benchmark itself is remarkably simple. The test builds three -1-dimensional arrays and loads the first two up with random floating-point -numbers. The arrays are then partitioned into 4 equal-sized groups, and the -test proceeds by performing addition, subtraction, multiplication, and -division -- one operation on each group. (For example, for the addition -group, an element from the first array is added to the second array and the -result is placed in the third array.) - -Of course, most of the work takes place inside the routines that perform the -addition, subtraction, multiplication, and division. These routines operate -on a special data type (referred to as an InternalFPF number) that -- though -not strictly IEEE compliant -- carries all the necessary data fields to -support an IEEE-compatible floating-point system. Specifically, an -InternalFPF number is built up of the following fields: - -Type (indicates a NORMAL, SUBNORMAL, etc.) - -Mantissa sign - -Unbiased, signed 16-bit exponent - -4-word (16 bits) mantissa. - -The emulated floating-point test reports its results in number of loops per -second (where a "loop" is one pass through the arrays as described above). - -Finally, we are aware that this test could be on its way to becoming an -anachronism. A growing number of systems are appearing that have -coprocessors built into the main CPU. It's possible that floating-point -emulation will one day be a thing of the past. - -Analysis - -Optimized 486 code (Watcom C/C++ 10.0): The algorithm's time is distributed -across a number of routines. The distribution is: - -ShiftMantLeft1() - 60% of the time - -ShiftMantRight1() - 17% of the time - -DivideInternalFPF() - 14% of the time - -MultiplyInternalFPF() - 5% of the time. - -The first two routines are similar to one another; both shift bits about in -a floating-point number's mantissa. It's reasonable that ShiftMantLeft1() -should take a larger share of the system's time; it is called as part of the -normalization process that concludes every emulated addition, subtraction, -mutiplication, and division. - -680x0 Code (Macintosh CodeWarrior): CodeWarrior's profiler is -function-based; consequently, it isn't possible to get timing at the machine -instruction level. However, the output to CodeWarrior's profiler has -provided insight into the breakdown of time spent in various functions that -forces us to rethink our 486 code analysis. - -Analyzing what goes on inside the emulated floating-point tests is a tough -one to call because some of the routines that are part of the test are -called by the function that builds the arrays. Consequently, a quick look at -the profiler's output can be misleading; it's not obvious how much time a -particular routine is spending in the test and how much time that same -routine is spending setting up the test (an operation that does not get -timed). - -Specifically, the routine that loads up the arrays with test data calls -LongToInternalFPF() and DivideInternalFPF(). LongToInternalFPF() makes one -call to normalize() if the number is not a true zero. In turn, normalize() -makes an indeterminate number of calls to ShiftMantLeft1(), depending on the -structure of the mantissa being normalized. - -What's worse, DivideInternalFPF() makes all sorts of calls to all kinds of -important low-level routines such as Sub16Bits() and ShiftMantLeft1(). -Untangling the wiring of which routine is being called as part of the test, -and which is being called as part of the setup could probably be done with -the computer equivalent of detective work and spelunking, but in the -interest of time we'll opt for approximation. - -Here's a breakdown of some of the important routines and their times: - -AddSubInternalFPF() - 1003.9 microsecs (called 9024 times) - -MultiplyInternalFPF() - 20143 microsecs (called 5610 times) - -DivideInternalFPF() - 18820.9 microsecs (called 3366 times). - -The 3366 calls to DivideInternalFPF() are timed calls, not setup calls -- -the profiler at least gives outputs of separate calls made to the same -routine, so we can determine which call is being made by the benchmark, and -which is being made by the setup routine. It turns out that the setup -routine calls DivideInternalFPF() 30,000 times. - -Notice that though addition/subtraction are called most often, -multiplication next, then finally division; the time spent in each is the -reverse. Division takes the most time, then multiplication, finally -addition/subtraction. (There's probably some universal truth lurking here -somewhere, but we haven't found it yet.) - -Other routines, and their breakdown: - -Add16Bits() - 115.3 microsecs - -ShiftMantRight1() - 574.2 microsecs - -Sub16Bits() - 1762 microsecs - -StickySiftRightMant - 40.4 microsecs - -ShiftMantLeft1() - 17486.1 microsecs - -The times for the last three routines are suspect, since they are called by -DivideInternalFPF(), and a large portion of their time could be part of the -setup process. This is what leads us to question the results obtained in the -486 analysis, since it, too, is unable to determine precisely who is calling -whom. - -Porting Considerations - -Earlier versions of this benchmark were extremely sensitive to porting; -particularly to the "endianism" of the target system. We have tried to -eliminate many of these problems. The test is nonetheless more "sensitive" -to porting than most others. - -Pay close attention to the following defines and typedefs. They can be found -in the files EMFLOAT.H, NMGLOBAL.H, and NBENCH1.H: - -u8 - Stands for unsigned, 8-bit. Usually defined to be unsigned char. - -u16 - Stands for unsigned, 16-bit. Usually defined to be unsigned short. - -u32 - Stands for unsigned, 32-bit. Usually defined to be unsigned long. - -INTERNAL_FPF_PRECISION - Indicates the number of elements in the mantissa of -an InternalFPF number. Should be set to 4. - -The exponent field of an InternalFPF number is of type short. It should be -set to whatever minimal data type can hold a signed, 16-bit number. - -Other global definitions you will want to be aware of: - -CPUEMFLOATLOOPMAX - Sets the maximum number of loops the benchmark will -attempt before flagging an error. Each execution of a loop in the emulated -floating-point test is "non-destructive," since the test takes factors from -two arrays, operates on the factors, and places the result in a third array. -Consequently, the test makes more work for itself by increasing the number -of times it passes through the arrays (# of loops). If the system exceeds -the limit set by CPUEMFLOATLOOPMAX, it will signal an error. - -This value may be altered to suit your system; it will not effect the -benchmark results (unless you reduce it so much the system can never -generate enough loops to produce a good test run). - -EMFARRAYSIZE - Sets the size of the arrays to be used in the test. This -value is the number of entries (InternalFPF numbers) per array. Currently, -the number is fixed at 3000, and should not be altered. - -Currently, there is no means of testing correct execution of the benchmark -other than via debugger. There are routines available to decode the internal -floating point format and print out the numbers, but no formal correctness -test has been constructed. (This should be available soon. -- 3/14/95 RG) - -** It now prints out the operations of 8 of the entries used in the -** test. Assuming you leave EMFARRAYSIZE at 3000, your results should -** look like the ones below. The number in front of the colon is the -** index of the entry. -** -** 2: (-1.1160E 0) + (-4.5159E 0) = -5.6320E 0 -** 6: (-4.4507E -1) - (-8.2050E -1) = +3.7543E -1 -** 10: (+1.2465E 0) * (+7.4667E -1) = +9.3075E -1 -** 14: (-1.2781E 0) / (-1.7367E 0) = +7.3596E -1 -** 2986: (-7.0390E 0) * (-2.0752E 0) = +1.4607E 1 -** 2990: (+8.3753E -1) / (+2.3876E 1) = +3.5078E -2 -** 2994: (-1.1393E 0) + (-1.6080E 1) = -1.7219E 1 -** 2998: (+7.2450E 0) - (-8.2654E -1) = +8.0716E 0 -** -** Uwe F. Mayer - -References - -Microprocessor Programming for Computer Hobbyists, Neill Graham, Tab Books, -Blue Ridge Summit, PA, 1977. - -Apple Numerica Manual, Second edition, Apple Computer, Addison-Wesley -Publishing Co., Reading, MA, 1988. - -Fourier Series - -Description - -This is a floating-point benchmark designed primarily to exercise the -trigonometric and transcendental functions of the system. It calculates the -first n Fourier coefficients of the function (x+1)x on the interval 0,2. In -this case, the function (x+1)x is being treated as a cyclic waveform with a -period of 2. - -The Fourier coefficients, when applied as factors to a properly constructed -series of sine and cosine functions, allow you to approximate the original -waveform. (In fact, if you can calculate all the Fourier coefficients -- -there'll be an infinite number -- you can reconstruct the waveform exactly). -You have to calculate the coefficients via integration, and the algorithm -does this using a simple trapezoidal rule for its numeric integration -function. - -The upshot of all this is that it provides an exercise for the -floating-point routines that calculate sine, cosine, and raising a number to -a power. There are also some floating-point multiplications, divisions, -additions, and subtractions mixed in. - -The benchmark reports its results as the number of coefficients calculated -per second. - -As an additional note, we should point out that the performance of this -benchmark is heavily dependent on how well-built the compiler's math library -is. We have seen at least two cases where recompilation with new (and -improved!) math libraries have resulted in two-fold and five-fold -performance improvements. (Apparently, when a compiler gets moved to a new -platform, the trigonometric and transcendental functions in the math -libraries are among the last routines to be "hand optimized" for the new -platform.) About all we can say about this is that whenever you run this -test, verify that you have the latest and greatest math libraries. - -Analysis - -Optimized 486 code: The benchmark partitions its time almost evenly among -the modules pow387, exp386, and trig387; giving between 25% and 28% of its -time to each. This is based on profiling with the Watcom compiler running -under Windows NT. These modules hold the routines that handle raising a -number to a power and performing trigonometric (sine and cosine) -calculations. For example, within trig387, time was nearly equally divided -between the routine that calculates sine and the routine that calculates -cosine. - -The remaining time (between 17% and 18%) was spent in the balance of the -test. We noticed that most of that time occurred in the routine -thefunction(). This is at the heart of the numerical integration routine the -benchmark uses. - -Consequently, this benchmark should be a good test of the exponential and -trigonometric capabilities of a processor. (Note that we recognize that the -performance also depends on how well the compiler's math library is built.) - -680x0 Code (Macintosh CodeWarrior): The CodeWarrior profiler is function -based, therefore it is impossible to get performance results for individual -machine instructions. The CodeWarrior compiler is also unable to tell us how -much time is spent within a given library routine; we can't see how much -time gets spent executing the sin(), cos(), or pow() functions (which, -unfortunately, was the whole idea behind the benchmark). - -About all we can glean from the results is that thefunction() takes about -74% of the time in the test (this is where the heavy math calculations take -place) while trapezoidintegrate() accounts for about 26% of the time on its -own. - -Porting Considerations - -Necessarily, this benchmark is at the mercy of the efficiency of the -floating-point support provided by whatever compiler you are using. It is -recommended that, if you are doing the port yourself, you contact the -designers of the compiler, and discuss with them what optimization switches -should be set to produce the fastest code. (This sounds simple; usually it's -not. Some systems let you decide between speed and true IEEE compliance.) - -As far as global definitions go, this benchmark is happily free of them. All -the math is done using double data types. We have noticed that, on some Unix -systems, you must be careful to include the correct math libraries. -Typically, you'll discover this at link time. - -To test for correct execution of the benchmark: It's unlikely you'll need to -do this, since the algorithm is so cut-and-dried. Furthermore, there are no -explicit provisions made to verify the correctness. You can, however, either -dip into your favorite debugger, or alter the code to print out the contents -of the abase (which holds the A[i] terms) and bbase (which holds the B[i] -terms) arrays as they are being filled (see routine DoFPUTransIteration). -** This is exactly what I have done, it now prints out A[i] and B[i] data. -** Uwe F. Mayer -Run the benchmark with a command file set to execute only the Fourier test, -and examine the contents of the arrays. The first 100 are listed below. - -A[i]= - 2.84 1.05 0.274 0.0824 0.0102 -0.024 -0.0426 -0.0536 -0.0605 -0.065 --0.0679 -0.0698 -0.0709 -0.0715 -0.0717 -0.0715 -0.0711 -0.0704 --0.0696 -0.0685 -0.0674 -0.0661 -0.0647 -0.0632 -0.0615 -0.0598 -0.058 --0.0561 -0.0542 -0.0521 -0.0501 -0.0479 -0.0457 -0.0434 -0.0411 --0.0387 -0.0363 -0.0338 -0.0313 -0.0288 -0.0262 -0.0236 -0.0209 --0.0183 -0.0156 -0.0129 -0.0102 -0.00744 -0.0047 -0.00196 0.000794 -0.00355 0.0063 0.00905 0.0118 0.0145 0.0172 0.0199 0.0226 0.0253 -0.0279 0.0305 0.0331 0.0357 0.0382 0.0407 0.0431 0.0455 0.0479 0.0502 -0.0525 0.0547 0.0569 0.059 0.061 0.063 0.0649 0.0668 0.0686 0.0703 -0.072 0.0736 0.0751 0.0765 0.0779 0.0792 0.0804 0.0816 0.0826 0.0836 -0.0845 0.0853 0.0861 0.0867 0.0873 0.0877 0.0881 0.0884 0.0887 0.0888 - -B[i]= -(undefined) -1.88 -1.16 -0.806 -0.61 -0.487 -0.402 -0.34 -0.293 -0.255 --0.224 -0.199 -0.177 -0.158 -0.141 -0.126 -0.113 -0.101 -0.0901 --0.0802 -0.071 -0.0625 -0.0546 -0.0473 -0.0404 -0.034 -0.0279 -0.0222 --0.0168 -0.0117 -0.00693 -0.00238 0.00193 0.00601 0.00988 0.0135 0.017 -0.0203 0.0234 0.0263 0.0291 0.0317 0.0341 0.0364 0.0385 0.0405 0.0424 -0.0441 0.0457 0.0471 0.0484 0.0496 0.0507 0.0516 0.0525 0.0532 0.0538 -0.0543 0.0546 0.0549 0.055 0.0551 0.055 0.0549 0.0546 0.0543 0.0538 -0.0533 0.0527 0.052 0.0512 0.0503 0.0493 0.0483 0.0472 0.046 0.0447 -0.0434 0.042 0.0405 0.039 0.0374 0.0358 0.0341 0.0323 0.0305 0.0287 -0.0268 0.0249 0.023 0.021 0.019 0.0169 0.0149 0.0128 0.0107 0.00857 -0.00644 0.0043 0.00215 - -Note that there is no B[0] coefficient. If the above numbers are in the -arrays shown, you can feel pretty confident that the benchmark it working -properly. - -References - -Engineering and Scientific Computations in Pascal, Lawrence P. Huelsman, -Harper & Row, New York, 1986. - -Assignment Algorithm - -Description - -This test is built on an algorithm with direct application to the business -world. The assignment algorithm solves the following problem: Say you have X -machines and Y jobs. Any of the machines can do any of the jobs; however, the -machines are sufficiently different so that the cost of doing a particular -job can vary depending what machine does it. Furthermore, the jobs are -sufficiently different that the cost varies depending on which job a given -machine does. You therefore construct a matrix; machines are the rows, jobs -are the columns, and the [i,j] element of the array is the cost of doing the -jth job on the ith machine. How can you assign the jobs so that the cost of -completing them all is minimal? (This also assumes that one machine does one -job.) - -Did you get that? - -The assignment algorithm benchmark is largely a test of how well the -processor handles problems built around array manipulation. It is not a -floating-point test; the "cost matrix" built by the algorithm is simply a 2D -array of long integers. This benchmark considers an iteration to be a run of -the assignment algorithm on a 101 x 101 - element matrix. It reports its -results in iterations per second. - -Analysis - -Optimized 486 code (Watcom C/C++ 10.0): There are numerous loops within the -assignment algorithm. The development system we were using (Watcom C/C++ -10.0) appears to have a fine time unrolling many of them. Consequently, it -is difficult to pin down the execution impact of single lines (as in, for -example, the numeric sort benchmark). - -On the level of functions, the benchmark spends around 70% of its time in -the routine first_assignments(). This is where a) lone zeros in rows and -columns are found and selected, and b) a choice is made between duplicate -zeros. Around 23% of the time is spent in the second_assignments() routine -where (if first_assignments() fails) the matrix is partitioned into smaller -submatrices. - -Overall, we did a tally of instruction mix execution. The approximate -breakdowns are: - -move - 38% - -conditional jump - 12% - -unconditional jump - 11% - -comparison - 14% - -math/logical/shift - 24% - -Many of the move instructions that appeared to consume the most amounts of -time were referencing items on the local stack frame. This required an -indirect reference through EBP, plus a constant offset to resolve the -address. - -This should be a good exercise of a cache, since operations in the -first_assignments() routine require both row-wise and column-wise movement -through the array. Note that the routine could be made more "severe" by -chancing the assignedtableau[][] array to an array of unsigned char -- -forcing fetches on byte boundaries. - -680x0 Code (CodeWarrior): The CodeWarrior profiler is function-based. -Consequently, it's not possible to determine what's going on at the machine -instruction level. We can, however, get a good idea of how much time the -algorithm spends in each routine. The important routines are broken down as -follows: - -calc_minimum_costs() - approximately 0.3% of the time - -(250 microsecs) - -first_assignments() - approximately 79% of the time - -(96284.6 microsecs) - -second_assignments() - approximately 19% of the time - -(22758 microsecs) - -These times are approximate; some time is spent in the Assignment() routine -itself. - -These figures are reasonably close to those of the 486, at least in terms of -the mixture of time spent in a particular routine. Hence, this should still -be a good test of system cache (as described in the preceding section), -given the behavior of the first_assignments() routine. - -Porting Considerations - -The assignment algorithm test is purely an integer benchmark, and requires -no special data types that might be affected by ports to different -architectures. There are only two global constants that affect the -algorithm: - -ASSIGNROWS and ASSIGNCOLS - These set the size of the assignment array. Both -are defined to be 101 (so, the array that is benchmarked is a 101 x 101 --element array of longs). These values should not be altered. - -To test for correct execution of the benchmark: #define the symbol DEBUG, -recompile, set up a command file that executes only the assignment -algorithm, and run the benchmark. (You may want to pipe the output through a -paging filter, like the more program.) The act of defining DEBUG will enable -a section of code that displays the assigned columns on a per-row basis. If -the benchmark is working properly, the numbers to be displayed -should be: - -R000: 056 R001: 066 R002: 052 R003: 065 R004: 043 R005: 023 R006: 016 -R007: 077 R008: 095 R009: 004 R010: 064 R011: 076 R012: 078 R013: 091 -R014: 013 R015: 029 R016: 044 R017: 014 R018: 041 R019: 042 R020: 020 -R021: 071 R022: 024 R023: 017 R024: 055 R025: 040 R026: 070 R027: 025 -R028: 031 R029: 019 R030: 073 R031: 002 R032: 047 R033: 009 R034: 035 -R035: 045 R036: 005 R037: 063 R038: 081 R039: 039 R040: 087 R041: 008 -R042: 053 R043: 093 R044: 049 R045: 092 R046: 061 R047: 046 R048: 026 -R049: 034 R050: 088 R051: 000 R052: 028 R053: 018 R054: 072 R055: 021 -R056: 037 R057: 082 R058: 006 R059: 058 R060: 096 R061: 068 R062: 069 -R063: 054 R064: 057 R065: 086 R066: 097 R067: 084 R068: 099 R069: 051 -R070: 098 R071: 003 R072: 074 R073: 062 R074: 080 R075: 033 R076: 011 -R077: 094 R078: 012 R079: 050 R080: 010 R081: 038 R082: 089 R083: 059 -R084: 022 R085: 079 R086: 015 R087: 007 R088: 075 R089: 083 R090: 060 -R091: 048 R092: 032 R093: 067 R094: 001 R095: 030 R096: 027 R097: 085 -R098: 090 R099: 036 R100: 100 - -These are the column choices for each row made by the algorithm. If -you see these numbers displayed, the algorithm is working correctly. - -*** The original debugging information was incorrect, as it not only -*** display the chosen columns, but also displayed eliminated columns. -*** Changed to show all 101 entries. Uwe F. Mayer - -References - -Quantitative Decision Making for Business, Gordon, Pressman, and Cohn, -Prentice-Hall, Englewood Cliffs, NJ, 1990. - -Quantitative Decision Making, Guiseppi A. Forgionne, Wadsworth Publishing -Co., California, 1986. - -Huffman Compression - -Description - -This is a compression algorithm that -- while helpful for some time as a -text compression technique -- has since fallen out of fashion on account of -the superior performance by algorithms such as LZW compression. It is, -however, still used in some graphics file formats in one form or another. - -The benchmark consists of three parts: - -Building a "Huffman Tree" (explained below), - -Compression, and - -Decompression. - -A "Huffman Tree" is a special data structure that guides the compression and -decompression processes. If you were to diagram one, it would look like a -large binary tree (i.e., two branches per each node). Describing its -function in detail is beyond the scope of this paper (see the references for -more information). We should, however, point out that the tree is built from -the "bottom up"; and the procedure for constructing it requires that the -algorithm scan the uncompressed buffer, building a frequency table for all -the characters appearing in the buffer. (This version of the Huffman -algorithm compresses byte-at-a-time, though there's no reason why the same -principle could not be applied to tokens larger than one byte.) - -Once the tree is built, text compression is relatively straightforward. The -algorithm fetches a character from the uncompressed buffer, navigates the -tree based on the character's value, and produces a bit stream that is -concatenated to the compressed buffer. Decompression is the reverse of that -process. (We recognize that we are simplifying the algorithm. Again, we -recommend you check the references.) - -The Huffman Compression benchmark considers an iteration to be the three -operations described above, performed on an uncompressed text buffer of 5000 -bytes. It reports its results in iterations per second. - -Analysis - -Optimized 486 code (Watcom C/C++ 10.0): The Huffman compression algorithm -- -tree building, compression, and decompression -- is written as a single, -large routine: DoHuffIteration(). All the benchmark's time is spent within -that routine. - -Components of DoHuffIteration() that consume the most time are those that -perform the compression and decompression . - -The code for performing the compression spends most of its time (accounting -for about 13%) constructing the bit string for a character that is being -compressed. It does this by seeking up the tree from a leaf, emitting 1's -and 0's in the process, until it reaches the root. The stream of 1's and 0's -are loaded into a character array; the algorithm then walks "backward" -through the array, setting (or clearing) bits in the compression buffer as -it goes. - -Similarly, the decompression portion takes about 12% of the time as the -algorithm pulls bits out of the compressed buffer -- using them to navigate -the Huffman tree -- and reconstructs the original text. - -680x0 Code (Macintosh CodeWarrior): CodeWarrior's profiler is function -based. Consequently, it's impossible to get performance scores for -individual machine instructions. Furthermore, as mentioned above, the -Huffman compression algorithm is written as a monolithic routine. This makes -the results from the CodeWarrior profiler all the more sparse. - -We can at least point out that the lowmost routines (GetCompBit() and -SetCompBit()) that read and write individual bits, though called nearly 13 -million times each, account for only 0.7% and 0.3% of the total time, -respectively. - -Porting Considerations - -The Huffman algorithm relies on no special data types. It should port -readily. Global constants of interest include: - -EXCLUDED - This is a large, positive value. Currently it is set to 32000, -and should be left alone. Basically, this is a token that the system uses to -indicate an excluded character (one that does not appear in the plain-text). -It is set to a ridiculously high value that will never appear in the -pointers of the tree during normal construction. - -MAXHUFFLOOPS - This is another one of those "governor" constants. The -Huffman benchmark creates more work for itself by doing multiple -compression/decompression loops. This constant sets the maximum number of -loops it will attempt per iteration before it gives up. Currently, it is set -to 50000. Though it is unlikely you'll ever need to modify this value, you -can increase it if your machine is too fast for the adjustment algorithm. Do -not reduce the number. - -HUFFARRAYSIZE - This value sets the size of the plain-text array to be -compressed. You can override this value with the command file to see how -well your machine performs for larger or smaller arrays. The subsequent -results, however, are invalid for comparison with other systems. - -To test for correct execution of the benchmark: #define the symbol DEBUG, -recompile, build a command file that executes only the Huffman compression -algorithm, and run the benchmark. Defining DEBUG will enable a section of -code that verifies the decompression as it takes place (i.e., the routine -compares -- character at a time -- the uncompressed data with the original -plain-text). If there's an error, the program will repeatedly display: "Error -at textoffset xxx". - -** If everything is correct it will emit quite a few "Huffman: OK" messages. -** -** I added a resetting of the random number generator, outside of the -** timed loop, and a resetting of the Huffman tree, inside of the -** timed loop. That should help to make the benchmark more consistent. -** The program did originally only reset half of the tree, which lead -** to runtime errors on some systems. The effect on the benchmark -** should be negligible, and in fact comes out as being of the order -** of less than 1% on my test system. -** Uwe F. Mayer - -References - -Data Compression: Methods and Theory, James A. Storer, Computer Science -Press, Rockville, MD, 1988. - -An Introduction to Text Processing, Peter D. Smith, MIT Press, Cambridge, -MA, 1990. - -IDEA Encryption - -Description - -This is another benchmark based on a "higher-level" algorithm; "higher --level" in the sense that it is more complex than a sort or a search -operation. - -Security -- and, therefore, cryptography -- are becoming increasingly -important issues in the computer realm. It's likely that more and more -machines will be running routines like the IDEA encryption algorithm. (IDEA -is an acronym for the International Data Encryption Algorithm.) - -A good description of the algorithm (and, in fact, the reference we used to -create the source code for the test) can be found in Bruce Schneier's -exhaustive exploration of encryption, "Applied Cryptography" (see -references). To quote Mr. Schneier: "In my opinion, it [IDEA] is the best -and most secure block algorithm available to the public at this time." - -IDEA is a symmetrical, block cipher algorithm. Symmetrical means that the -same routine used to encrypt the data also decrypts the data. A block cipher -works on the plain-text (the message to be encrypted) in fixed, discrete -chunks. In the case of IDEA, the algorithm encrypts and decrypts 64 bits at -a time. - -As pointed out in Schneier's book, there are three operations that the IDEA -uses to do its work: - -XOR (exclusive-or) - -Addition modulo 216 (ignoring overflow) - -Multiplication modulo 216+1 (ignoring overflow). - -IDEA requires a key of 128 bits. However, keys and blocks are further -subdivided into 16-bit chunks, so that any given operation within the IDEA -encryption is performed on 16-bit quantities. (This is one of the many -advantages of the algorithm, it is efficient even on 16-bit processors.) - -The IDEA benchmark considers an "iteration" to be an encryption and -decryption of a buffer of 4000 bytes. The test actually builds 3 buffers: -The first to hold the original plain-text, the second to hold the encrypted -text, and the third to hold the decrypted text (the contents of which should -match that of the first buffer). It reports its results in iterations per -second. - -Analysis - -Optimized 486 code: The algorithm actually spends most of its time (nearly -75%) within the mul() routine, which performs the multiplication modulo -216+1. This is a super-simple routine, consisting primarily of if -statements, shifts, and additions. - -The remaining time (around 24%) is spent in the balance of the cipher_idea() -routine. (Note that cipher_idea() calls the mul() routine frequently; so, -the 24% is comprised of the other lines of cipher_idea()). cipher_idea() is -littered with simple pointer-fetch-and-increment operations, some addition, -and some exclusive-or operations. - -Note that IDEA's exercise of system capabilities probably doesn't extend -beyond testing simple integer math operations. Since the buffer size is set -to 4000 bytes, the test will run entirely in processor cache on most -systems. Even the cache won't get a heavy "internal" workout, since the -algorithm proceeds sequentially through each buffer from lower to higher -addresses. - -680x0 code (Macintosh CodeWarrior): CodeWarrior's profiler is function -based; consequently, it is impossible to determine execution profiles for -individual machine instructions. We can, however, get an idea of how much -time is spent in each routine. - -As with Huffman compression, the IDEA algorithm is written monolithically -- -a single, large routine does most of the work. However, a special -multiplication routine, mul(), is frequently called within each -encryption/decryption iteration (see above). - -In this instance, the results for the 68K system diverges widely from those -of the 486 system. The CodeWarrior profiler shows the mul() routine as -taking only 4% of the total time in the benchmark, even though it is called -over 20 million times. The outer routine is called 600,000 times, and -accounts for about 96% of the whole program's entire time. - -Porting Considerations - -Since IDEA does its work in 16-bit units, it is particularly important that -u16 be defined to whatever datatype provides an unsigned 16-bit integer on -the test platform. Usually, unsigned short works for this. (You can verify -the size of a short by running the benchmarks with a command file that -includes ALLSTATS=T as one of the commands. This will cause the benchmark -program to display a message that tells the size of the int, short, and long -data-types in bytes.) - -Also, the mul() routine in IDEA requires the u32 datatype to define an -unsigned 32-bit integer. In most cases, unsigned long works. - -To test for correct execution of the benchmark: #define the symbol DEBUG, -recompile, build a command file that executes only the IDEA algorithm, and -run the benchmark. Defining DEBUG will enable a section of code that -compares the original plain-text with the output of the test. (Remember, the -benchmark performs both encryption and decryption.) If the algorithm has -failed, the output will not match the input, and you'll see "IDEA Error" -messages all over your display. - -References - -Applied Cryptography: Protocols, Algorithms, and Source Code in C, Bruce -Schneier, John Wiley & Sons, Inc., New York, 1994. - -Neural Net - -Description - -The Neural Net simulation benchmark is based on a simple back-propagation -neural network presented by Maureen Caudill as part of a BYTE article that -appeared in the October, 1991 issue (see "Expert Networks" in that issue). -The network involved is a simple 3-layer (input neurodes, middle-layer -neurodes, and output neurodes) network that accepts a number of 5 x 7 input -patterns and produce a single 8-bit output pattern. - -The test involves sending the network an input pattern that is the 5 x 7 -"image" of a character (1's and 0's -- 1's representing lit pixels, 0's -representing unlit pixels), and teaching it the 8-bit ASCII code for the -character. - -A thorough description of how the back propagation algorithm works is beyond -the scope of this paper. We recommend you search through the references -given at the end of this paper, particularly Ms. Caudill's article, for -detailed discussion. In brief, the benchmark is primarily an exercise in -floating-point operations, with some frequent use of the exp() function. It -also performs a great deal of array references, though the arrays in use are -well under 300 elements each (and less than 100 in most cases). - -The Neural Net benchmark considers an iteration to be a single learning -cycle. (A "learning cycle" is defined as the time it takes the network to be -able to associate all input patterns to the correct output patterns within a -specified tolerance.) It reports its results in iterations per second. - -Analysis - -Optimized 486 code: The forward pass of the network (i.e., calculating -outputs from inputs) utilize a sigmoid function. This function has, at its -heart, a call to the exp() library routine. A small but non-negligible -amount of time is spent in that function (a little over 5% for the 486 -system we tested). - -The learning portion of the network benchmark depends on the derivative of -the sigmoid function, which turns out to require only multiplications and -subtractions. Consequently, each learning pass exercises only simple -floating-point operations. - -If we divide the time spent in the test into two parts -- forward pass and -backward pass (the latter being the learning pass) -- then the test appears -to spend the greatest part of its time in the learning phase. In fact, most -time is spent in the adjust_mid_wts() routine. This is the part of the -routine that alters the weights on the middle layer neurodes. (It accounts -for over 40% of the benchmark's time.) - -680x0 Code (Macintosh CodeWarrior): Though CodeWarrior's profiler is -function based, the neural net benchmark is highly modular. We can therefore -get a good breakdown of routine usage: - -worst_pass_error() - 304 microsecs (called 4680 times) - -adjust_mid_wts() - 83277 microsecs (called 46800 times) - -adjust_out_wts() - 17394 microsecs (called 46800 times) - -do_mid_error() - 11512 microsecs (called 46800 times) - -do_out_error() - 3002 microsecs (called 46800 times) - -do_mid_forward() - 49559 microsecs (called 46800 times) - -do_out_forward() - 20634 microsecs (called 46800 times) - -Again, most time was spent in adjust_mid_wts() (as on the 486), accounting -for almost twice as much time as do_mid_forward(). - -Porting Consideration - -The Neural Net benchmark is not dependent on any special data types. There -are a number of global variables and arrays that should not be altered in -any way. Most importantly, the #defines found in NBENCH1.H under the Neural -Net section should not be changed. These control not only the number of -neurodes in each layer; they also include constants that govern the learning -processes. - -Other globals to be aware of: - -MAXNNETLOOPS - This constant simply sets the upper limit on the number of -training loops the test will permit per iteration. The Neural Net benchmark -adjusts its workload by re-teaching itself over and over (each time it -begins a new training session, the network is "cleared" -- loaded with -random values). It is unlikely you will ever need to modify this constant. - -inpath - This string pointer is set to the path from which the neural net's -input data is read. It is currently hardwired to "NNET.DAT". You shouldn't -have to change this name, unless your file system requires directory -information as part of the path. - -Note that the Neural Net benchmark is the only test that requires an -external data file. The contents of the file are listed in an attachment to -this paper. You should use the attachment to reconstruct the file should it -become lost or corrupted. Any changes to the file will invalidate the test -results. - -To test for correct execution of the benchmark: #define the symbol DEBUG, -recompile, build a command file that executes only the Neural Net test, and -run the benchmark. Defining DEBUG will enable a section of code that -displays how many passes through the learning process were required for the -net to learn. It should learn in 780 passes. - -References - -"Expert Networks," Maureen Caudill, BYTE Magazine, October, 1991. - -Simulating Neural Networks, Norbert Hoffmann, Verlag Vieweg, Wiesbaden, -1994. - -Signal and Image Processing with Neural Networks, Timothy Masters, John -Wiley and Sons, New York, 1994. - -Introduction to Neural Networks, Jeannette Stanley, California Scientific -Software, CA, 1989. - -LU Decomposition - -Description - -LU Decomposition is an algorithm that can be used as the heart of a program -for solving linear equations. Suppose you have a matrix A. LU Decomposition -determines the matrices L and U such that - -L . U = A - -where L is a lower triangular matrix and U is an upper triangular matrix. (A -lower triangular matrix has nonzero elements only on the main diagonal and -below. An upper triangular matrix has nonzero elements only on the main -diagonal and above.) - -Without going into the mathematical details too deeply, having the L and U -matrices makes the solution of linear equations (i.e., equations of the form -A . x = b) quite easy. It turns out that you can also use LU decomposition -to determine matrix inverses and determinants. - -The algorithm used in the benchmarks was derived from Numerical Recipes in -Pascal (there is a C version of the book, which we did not have on hand), a -book we heartily recommend to anyone serious about mathematical and -scientific computing. The authors are approving of LU decomposition as a -means of solving linear equations, pointing out that their version (which -makes use of what we would have to call "Crout's method with partial -implicit pivoting") is a factor of 3 better than one of their Gauss-Jordan -routines, a factor of 1.5 better than another. They go on to demonstrate the -use of LU decomposition for iterative improvement of linear equation -solutions. - -The benchmark begins by creating a "solvable" linear system. This is easily -done by loading up the column vector b with random integers, then -initializing A with an identity matrix. The equations are then "scrambled" -by either multiplying a row by a constant, or adding one row to another. The -scrambled matrices are handed to the LU algorithm. - -The LU Decomposition benchmark considers a single iteration to be the -solution of one set of equations (the size of A is fixed at 101 x 101 -elements). It reports its results in iterations per second. - -Analysis - -Optimized 486 code (Watcom C/C++ 10.0): The entire algorithm consists of two -parts: the LU decomposition itself, and the back substitution algorithm that -builds the solution vector. The majority of the algorithm's time takes place -within the former; the algorithm that builds the L and U matrices (this -takes place in routine ludcmp()). - -Within ludcmp(), there are two extremely tight for loops forming the heart -of Crout's algorithm that consume the majority of the time. The loops are -"tight" in that they each consist of only one line of code; in both cases, -the line of code is a "multiply and accumulate" operation (actually, it's -sort of a multiply and de-accumulate, since the result of the multiplication -is subtracted, not added). - -In both cases, the items multiplied are elements from the A array; and one -factor's row index is varying more rapidly, while another factor's column -index is varying more rapidly. - -Note that this is a good overall test of floating-point operations within -matrices. Most of the math is floating-point; primarily additions, -subtractions, and multiplications (only a few divisions). - -680x0 Code (Macintosh CodeWarrior): CodeWarrior's profiler is function -based. It is therefore impossible to determine execution profiles at the -machine-code level. The profiler does, however, allow us to determine how -much time the benchmark spends in each routine. This breakdown is as -follows: - -lusolve() - 3.4 microsecs (about 0% of the time) - -lubksb() 1198 microsec (about 2% of the time) - -ludcmp() - 63171 microsec (about 91% of the time) - -The above percentages are for the whole program. Consequently, as a portion -of actual benchmark time, the amount attributed to each will be slightly -larger (though the proportions will remain the same). - -Since ludcmp() performs the actual LU decomposition, this is exactly where -we'd want the benchmark to spend its time. The lubksb() routine calls -ludcmp(), using the resulting matrix to "back-solve" the linear equation. - -Porting Considerations - -The LU Decomposition routine requires no special data types, and is immune -to byte ordering. It does make use of a typedef (LUdblptr) that includes an -embedded union; this allows the benchmark to "coerce" a pointer to double -into a pointer to a 2D array of double. This arrangement has not caused -problems with the compilers we have tested to date. - -Other constants and globals to be aware of: - -LUARRAYROWS and LUARRAYCOLS - These constants set the size of the -coefficient matrix, A. They cannot be altered by command file. In fact, you -shouldn't alter them at all, or your results will be invalid. Currently, -they are both set to 101. - -MAXLUARRAYS - This is another "governor" constant. The algorithm performs -dynamic workload adjustment by building more and more arrays to solve per -timing round. This sets the maximum upper limit of arrays that it will -build. Currently, it is set to 1000, which should be more than enough for -the reasonable future (1000 arrays of 101 x 101 floating-point doubles would -require somewhere around 80 megabytes of RAM -- and that's not counting the -column vectors). - -To test for correct execution of the benchmark: Currently, there is no -simple technique for doing this. You can, however, either use your favorite -debugger (or embed a printf() statement) at the conclusion of the lubksb() -routine. When this routine concludes, the array b will hold the solution -vector. These items will be stored as floating-point doubles, and the first -14 are (with rounding): - -46 20 23 22 85 86 97 95 8 89 75 67 6 86 - -If you find these numbers as the first 14 in the array b[], then you're -virtually guaranteed that the algorithm is working correctly. - -*** The above is not correct, as the initial matrix is not the identity, -*** but a matrix with random nonzero entries on the diagonal (they have -*** altered the algorithm since they wrote the documentation). -*** I changed the output of the debugging routine, it now prints first -*** what the array b should hold (as righthand side divided by diagonal -*** entry), and then it prints what the array b does hold after the -*** decomposition has been done to compute the solution of the system. If -*** you get the same, then fine. -*** And, by the way, my original right hand sides are -*** 46 23 85 97 8 75 6 81 88 76 6 84 31 53 2 ... -*** and the diagonal entries are -*** 520 922 186 495 89 267 786 571 175 600 738 321 897 541 859 ... -*** You notice that one has every other number of the original sequence. -*** This is due to BYTE's change of the algorithm, as they now also use the -*** random number generator to generate the diagonal elements. -*** Here is the complete set of data: -*** 46/520=0.09 23/922=0.02 85/186=0.46 97/495=0.20 8/89=0.09 -*** 75/267=0.28 6/786=0.01 81/571=0.14 88/175=0.50 76/600=0.13 -*** 6/738=0.01 84/321=0.26 31/897=0.03 53/541=0.10 2/859=0.00 -*** 86/92=0.93 51/121=0.42 29/248=0.12 51/789=0.06 84/6=14.00 -*** 21/180=0.12 33/48=0.69 2/899=0.00 12/820=0.01 69/372=0.19 -*** 59/809=0.07 74/18=4.11 40/788=0.05 39/56=0.70 86/91=0.95 -*** 33/878=0.04 82/165=0.50 42/561=0.07 8/274=0.03 84/694=0.12 -*** 32/352=0.09 25/969=0.03 59/816=0.07 33/112=0.29 5/125=0.04 -*** 89/740=0.12 7/223=0.03 54/994=0.05 33/80=0.41 55/676=0.08 -*** 6/524=0.01 36/544=0.07 21/160=0.13 58/596=0.10 15/717=0.02 -*** 84/311=0.27 98/530=0.18 46/713=0.06 41/233=0.18 73/640=0.11 -*** 40/343=0.12 72/586=0.12 100/965=0.10 59/764=0.08 37/866=0.04 -*** 27/682=0.04 3/652=0.00 41/352=0.12 87/786=0.11 45/79=0.57 -*** 83/761=0.11 41/817=0.05 46/209=0.22 78/930=0.08 85/210=0.40 -*** 80/756=0.11 18/931=0.02 30/669=0.04 47/127=0.37 85/891=0.10 -*** 66/364=0.18 83/955=0.09 58/637=0.09 58/778=0.07 82/288=0.28 -*** 42/540=0.08 76/290=0.26 59/36=1.64 29/463=0.06 63/476=0.13 -*** 6/340=0.02 73/341=0.21 59/737=0.08 81/492=0.16 98/443=0.22 -*** 58/32=1.81 53/562=0.09 54/263=0.21 46/367=0.13 58/390=0.15 -*** 96/845=0.11 30/746=0.04 2/687=0.00 28/849=0.03 84/180=0.47 -*** 85/382=0.22 -*** Uwe F. Mayer - -References - -Numerical Recipes in Pascal: The Art of Scientific Computing, Press, -Flannery, Teukolsky, Vetterling, Cambridge University Press, New York, 1989. diff --git a/thirdparty/nbench-byte-2.2.3/debugbit.good.gz b/thirdparty/nbench-byte-2.2.3/debugbit.good.gz deleted file mode 100644 index fdc893ebc2d22011e3481dd7f938a2ce2c8147ac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1019 zcmb2|=HTeKTw=n+oRXSUnx2$dqL-eZpTh9=t|3>0fq?5lyXBD+jtbBCE$=y@W9kBy zMKAU|D-UKD@<@wUWn^GrFyLG9dtOLZI*^G19%w2kE!#F->!KuzF!eZhm|tDGHs6GL z1|m#a&zh9?TAmLgaGz1;GeQc^`k}kwuIQQT@lHLvAD&oS+wWDz2A3OUjE2A<4S@sB P2e^LvHY+m-urL4s@4+_f diff --git a/thirdparty/nbench-byte-2.2.3/emfloat.c b/thirdparty/nbench-byte-2.2.3/emfloat.c deleted file mode 100644 index 5e73890e405..00000000000 --- a/thirdparty/nbench-byte-2.2.3/emfloat.c +++ /dev/null @@ -1,1343 +0,0 @@ -/* -** emfloat.c -** Source for emulated floating-point routines. -** BYTEmark (tm) -** BYTE's Native Mode Benchmarks -** Rick Grehan, BYTE Magazine. -** -** Created: -** Last update: 3/95 -** -** DISCLAIMER -** The source, executable, and documentation files that comprise -** the BYTEmark benchmarks are made available on an "as is" basis. -** This means that we at BYTE Magazine have made every reasonable -** effort to verify that the there are no errors in the source and -** executable code. We cannot, however, guarantee that the programs -** are error-free. Consequently, McGraw-HIll and BYTE Magazine make -** no claims in regard to the fitness of the source code, executable -** code, and documentation of the BYTEmark. -** Furthermore, BYTE Magazine, McGraw-Hill, and all employees -** of McGraw-Hill cannot be held responsible for any damages resulting -** from the use of this code or the results obtained from using -** this code. -*/ - - -#include -#include -#include "nmglobal.h" -#include "emfloat.h" - -/* -** Floating-point emulator. -** These routines are only "sort of" IEEE-compliant. All work is -** done using an internal representation. Also, the routines do -** not check for many of the exceptions that might occur. -** Still, the external formats produced are IEEE-compatible, -** with the restriction that they presume a low-endian machine -** (though the endianism will not effect the performance). -** -** Some code here was based on work done by Steve Snelgrove of -** Orem, UT. Other code comes from routines presented in -** the long-ago book: "Microprocessor Programming for -** Computer Hobbyists" by Neill Graham. -*/ - -/************************** -** SetupCPUEmFloatArrays ** -*************************** -** Set up the arrays that will be used in the emulated -** floating-point tests. -** This is done by loading abase and bbase elements with -** random numbers. We use our long-to-floating point -** routine to set them up. -** NOTE: We really don't need the pointer to cbase...cbase -** is overwritten in the benchmark. -*/ -void SetupCPUEmFloatArrays(InternalFPF *abase, - InternalFPF *bbase, - InternalFPF *cbase, - ulong arraysize) -{ -ulong i; -InternalFPF locFPF1,locFPF2; -/* -** Reset random number generator so things repeat. Inserted by Uwe F. Mayer. -*/ -extern int32 randnum(int32 lngval); -randnum((int32)13); - -for(i=0;itype=IFPF_IS_ZERO; -dest->sign=sign; -dest->exp=MIN_EXP; -for(i=0;imantissa[i]=0; -return; -} - -/*************************** -** SetInternalFPFInfinity ** -**************************** -** Set an internal floating-point-format number to infinity. -** This can happen if the exponent exceeds MAX_EXP. -** As above, sign picks the sign of infinity. -*/ -static void SetInternalFPFInfinity(InternalFPF *dest, - uchar sign) -{ -int i; /* Index */ - -dest->type=IFPF_IS_INFINITY; -dest->sign=sign; -dest->exp=MIN_EXP; -for(i=0;imantissa[i]=0; -return; -} - -/********************** -** SetInternalFPFNaN ** -*********************** -** Set an internal floating-point-format number to Nan -** (not a number). Note that we "emulate" an 80x87 as far -** as the mantissa bits go. -*/ -static void SetInternalFPFNaN(InternalFPF *dest) -{ -int i; /* Index */ - -dest->type=IFPF_IS_NAN; -dest->exp=MAX_EXP; -dest->sign=1; -dest->mantissa[0]=0x4000; -for(i=1;imantissa[i]=0; - -return; -} - -/******************* -** IsMantissaZero ** -******************** -** Pass this routine a pointer to an internal floating point format -** number's mantissa. It checks for an all-zero mantissa. -** Returns 0 if it is NOT all zeros, !=0 otherwise. -*/ -static int IsMantissaZero(u16 *mant) -{ -int i; /* Index */ -int n; /* Return value */ - -n=0; -for(i=0;i=0;i--) -{ accum=mantissa[i]; - new_carry=accum & 0x8000; /* Get new carry */ - accum=accum<<1; /* Do the shift */ - if(*carry) - accum|=1; /* Insert previous carry */ - *carry=new_carry; - mantissa[i]=accum; /* Return shifted value */ -} -return; -} - -/******************** -** ShiftMantRight1 ** -********************* -** Shift a mantissa right by 1 bit. Provides carry, as -** above -*/ -static void ShiftMantRight1(u16 *carry, - u16 *mantissa) -{ -int i; /* Index */ -int new_carry; -u16 accum; - -for(i=0;i>1; - if(*carry) - accum|=0x8000; - *carry=new_carry; - mantissa[i]=accum; -} -return; -} - - -/***************************** -** StickyShiftMantRight ** -****************************** -** This is a shift right of the mantissa with a "sticky bit". -** I.E., if a carry of 1 is shifted out of the least significant -** bit, the least significant bit is set to 1. -*/ -static void StickyShiftRightMant(InternalFPF *ptr, - int amount) -{ -int i; /* Index */ -u16 carry; /* Self-explanatory */ -u16 *mantissa; - -mantissa=ptr->mantissa; - -if(ptr->type!=IFPF_IS_ZERO) /* Don't bother shifting a zero */ -{ - /* - ** If the amount of shifting will shift everyting - ** out of existence, then just clear the whole mantissa - ** and set the lowmost bit to 1. - */ - if(amount>=INTERNAL_FPF_PRECISION * 16) - { - for(i=0;imantissa[0] & 0x8000) == 0) -{ - carry = 0; - ShiftMantLeft1(&carry, ptr->mantissa); - ptr->exp--; -} -return; -} - -/**************** -** denormalize ** -***************** -** Denormalize an internal-representation number. This means -** shifting it right until its exponent is equivalent to -** minimum_exponent. (You have to do this often in order -** to perform additions and subtractions). -*/ -static void denormalize(InternalFPF *ptr, - int minimum_exponent) -{ -long exponent_difference; - -if (IsMantissaZero(ptr->mantissa)) -{ - printf("Error: zero significand in denormalize\n"); -} - -exponent_difference = ptr->exp-minimum_exponent; -if (exponent_difference < 0) -{ - /* - ** The number is subnormal - */ - exponent_difference = -exponent_difference; - if (exponent_difference >= (INTERNAL_FPF_PRECISION * 16)) - { - /* Underflow */ - SetInternalFPFZero(ptr, ptr->sign); - } - else - { - ptr->exp+=exponent_difference; - StickyShiftRightMant(ptr, exponent_difference); - } -} -return; -} - - -/********************* -** RoundInternalFPF ** -********************** -** Round an internal-representation number. -** The kind of rounding we do here is simplest...referred to as -** "chop". "Extraneous" rightmost bits are simply hacked off. -*/ -void RoundInternalFPF(InternalFPF *ptr) -{ -/* int i; */ - -if (ptr->type == IFPF_IS_NORMAL || - ptr->type == IFPF_IS_SUBNORMAL) -{ - denormalize(ptr, MIN_EXP); - if (ptr->type != IFPF_IS_ZERO) - { - - /* clear the extraneous bits */ - ptr->mantissa[3] &= 0xfff8; -/* for (i=4; imantissa[i] = 0; - } -*/ - /* - ** Check for overflow - */ -/* Does not do anything as ptr->exp is a short and MAX_EXP=37268 - if (ptr->exp > MAX_EXP) - { - SetInternalFPFInfinity(ptr, ptr->sign); - } -*/ - } -} -return; -} - -/******************************************************* -** ARITHMETIC OPERATIONS ON INTERNAL REPRESENTATION ** -*******************************************************/ - -/*************** -** choose_nan ** -**************** -** Called by routines that are forced to perform math on -** a pair of NaN's. This routine "selects" which NaN is -** to be returned. -*/ -static void choose_nan(InternalFPF *x, - InternalFPF *y, - InternalFPF *z, - int intel_flag) -{ -int i; - -/* -** Compare the two mantissas, -** return the larger. Note that we will be emulating -** an 80387 in this operation. -*/ -for (i=0; imantissa[i] > y->mantissa[i]) - { - memmove((void *)x,(void *)z,sizeof(InternalFPF)); - return; - } - if (x->mantissa[i] < y->mantissa[i]) - { - memmove((void *)y,(void *)z,sizeof(InternalFPF)); - return; - } -} - -/* -** They are equal -*/ -if (!intel_flag) - /* if the operation is addition */ - memmove((void *)x,(void *)z,sizeof(InternalFPF)); -else - /* if the operation is multiplication */ - memmove((void *)y,(void *)z,sizeof(InternalFPF)); -return; -} - - -/********************** -** AddSubInternalFPF ** -*********************** -** Adding or subtracting internal-representation numbers. -** Internal-representation numbers pointed to by x and y are -** added/subtracted and the result returned in z. -*/ -static void AddSubInternalFPF(uchar operation, - InternalFPF *x, - InternalFPF *y, - InternalFPF *z) -{ -int exponent_difference; -u16 borrow; -u16 carry; -int i; -InternalFPF locx,locy; /* Needed since we alter them */ - -/* -** Following big switch statement handles the -** various combinations of operand types. -*/ -switch ((x->type * IFPF_TYPE_COUNT) + y->type) -{ -case ZERO_ZERO: - memmove((void *)x,(void *)z,sizeof(InternalFPF)); - if (x->sign ^ y->sign ^ operation) - { - z->sign = 0; /* positive */ - } - break; - -case NAN_ZERO: -case NAN_SUBNORMAL: -case NAN_NORMAL: -case NAN_INFINITY: -case SUBNORMAL_ZERO: -case NORMAL_ZERO: -case INFINITY_ZERO: -case INFINITY_SUBNORMAL: -case INFINITY_NORMAL: - memmove((void *)x,(void *)z,sizeof(InternalFPF)); - break; - - -case ZERO_NAN: -case SUBNORMAL_NAN: -case NORMAL_NAN: -case INFINITY_NAN: - memmove((void *)y,(void *)z,sizeof(InternalFPF)); - break; - -case ZERO_SUBNORMAL: -case ZERO_NORMAL: -case ZERO_INFINITY: -case SUBNORMAL_INFINITY: -case NORMAL_INFINITY: - memmove((void *)y,(void *)z,sizeof(InternalFPF)); - z->sign ^= operation; - break; - -case SUBNORMAL_SUBNORMAL: -case SUBNORMAL_NORMAL: -case NORMAL_SUBNORMAL: -case NORMAL_NORMAL: - /* - ** Copy x and y to locals, since we may have - ** to alter them. - */ - memmove((void *)&locx,(void *)x,sizeof(InternalFPF)); - memmove((void *)&locy,(void *)y,sizeof(InternalFPF)); - - /* compute sum/difference */ - exponent_difference = locx.exp-locy.exp; - if (exponent_difference == 0) - { - /* - ** locx.exp == locy.exp - ** so, no shifting required - */ - if (locx.type == IFPF_IS_SUBNORMAL || - locy.type == IFPF_IS_SUBNORMAL) - z->type = IFPF_IS_SUBNORMAL; - else - z->type = IFPF_IS_NORMAL; - - /* - ** Assume that locx.mantissa > locy.mantissa - */ - z->sign = locx.sign; - z->exp= locx.exp; - } - else - if (exponent_difference > 0) - { - /* - ** locx.exp > locy.exp - */ - StickyShiftRightMant(&locy, - exponent_difference); - z->type = locx.type; - z->sign = locx.sign; - z->exp = locx.exp; - } - else /* if (exponent_difference < 0) */ - { - /* - ** locx.exp < locy.exp - */ - StickyShiftRightMant(&locx, - -exponent_difference); - z->type = locy.type; - z->sign = locy.sign ^ operation; - z->exp = locy.exp; - } - - if (locx.sign ^ locy.sign ^ operation) - { - /* - ** Signs are different, subtract mantissas - */ - borrow = 0; - for (i=(INTERNAL_FPF_PRECISION-1); i>=0; i--) - Sub16Bits(&borrow, - &z->mantissa[i], - locx.mantissa[i], - locy.mantissa[i]); - - if (borrow) - { - /* The y->mantissa was larger than the - ** x->mantissa leaving a negative - ** result. Change the result back to - ** an unsigned number and flip the - ** sign flag. - */ - z->sign = locy.sign ^ operation; - borrow = 0; - for (i=(INTERNAL_FPF_PRECISION-1); i>=0; i--) - { - Sub16Bits(&borrow, - &z->mantissa[i], - 0, - z->mantissa[i]); - } - } - else - { - /* The assumption made above - ** (i.e. x->mantissa >= y->mantissa) - ** was correct. Therefore, do nothing. - ** z->sign = x->sign; - */ - } - - if (IsMantissaZero(z->mantissa)) - { - z->type = IFPF_IS_ZERO; - z->sign = 0; /* positive */ - } - else - if (locx.type == IFPF_IS_NORMAL || - locy.type == IFPF_IS_NORMAL) - { - normalize(z); - } - } - else - { - /* signs are the same, add mantissas */ - carry = 0; - for (i=(INTERNAL_FPF_PRECISION-1); i>=0; i--) - { - Add16Bits(&carry, - &z->mantissa[i], - locx.mantissa[i], - locy.mantissa[i]); - } - - if (carry) - { - z->exp++; - carry=0; - ShiftMantRight1(&carry,z->mantissa); - z->mantissa[0] |= 0x8000; - z->type = IFPF_IS_NORMAL; - } - else - if (z->mantissa[0] & 0x8000) - z->type = IFPF_IS_NORMAL; - } - break; - -case INFINITY_INFINITY: - SetInternalFPFNaN(z); - break; - -case NAN_NAN: - choose_nan(x, y, z, 1); - break; -} - -/* -** All the math is done; time to round. -*/ -RoundInternalFPF(z); -return; -} - - -/************************ -** MultiplyInternalFPF ** -************************* -** Two internal-representation numbers x and y are multiplied; the -** result is returned in z. -*/ -static void MultiplyInternalFPF(InternalFPF *x, - InternalFPF *y, - InternalFPF *z) -{ -int i; -int j; -u16 carry; -u16 extra_bits[INTERNAL_FPF_PRECISION]; -InternalFPF locy; /* Needed since this will be altered */ -/* -** As in the preceding function, this large switch -** statement selects among the many combinations -** of operands. -*/ -switch ((x->type * IFPF_TYPE_COUNT) + y->type) -{ -case INFINITY_SUBNORMAL: -case INFINITY_NORMAL: -case INFINITY_INFINITY: -case ZERO_ZERO: -case ZERO_SUBNORMAL: -case ZERO_NORMAL: - memmove((void *)x,(void *)z,sizeof(InternalFPF)); - z->sign ^= y->sign; - break; - -case SUBNORMAL_INFINITY: -case NORMAL_INFINITY: -case SUBNORMAL_ZERO: -case NORMAL_ZERO: - memmove((void *)y,(void *)z,sizeof(InternalFPF)); - z->sign ^= x->sign; - break; - -case ZERO_INFINITY: -case INFINITY_ZERO: - SetInternalFPFNaN(z); - break; - -case NAN_ZERO: -case NAN_SUBNORMAL: -case NAN_NORMAL: -case NAN_INFINITY: - memmove((void *)x,(void *)z,sizeof(InternalFPF)); - break; - -case ZERO_NAN: -case SUBNORMAL_NAN: -case NORMAL_NAN: -case INFINITY_NAN: - memmove((void *)y,(void *)z,sizeof(InternalFPF)); - break; - - -case SUBNORMAL_SUBNORMAL: -case SUBNORMAL_NORMAL: -case NORMAL_SUBNORMAL: -case NORMAL_NORMAL: - /* - ** Make a local copy of the y number, since we will be - ** altering it in the process of multiplying. - */ - memmove((void *)&locy,(void *)y,sizeof(InternalFPF)); - - /* - ** Check for unnormal zero arguments - */ - if (IsMantissaZero(x->mantissa) || IsMantissaZero(y->mantissa)) - SetInternalFPFInfinity(z, 0); - - /* - ** Initialize the result - */ - if (x->type == IFPF_IS_SUBNORMAL || - y->type == IFPF_IS_SUBNORMAL) - z->type = IFPF_IS_SUBNORMAL; - else - z->type = IFPF_IS_NORMAL; - - z->sign = x->sign ^ y->sign; - z->exp = x->exp + y->exp ; - for (i=0; imantissa[i] = 0; - extra_bits[i] = 0; - } - - for (i=0; i<(INTERNAL_FPF_PRECISION*16); i++) - { - /* - ** Get rightmost bit of the multiplier - */ - carry = 0; - ShiftMantRight1(&carry, locy.mantissa); - if (carry) - { - /* - ** Add the multiplicand to the product - */ - carry = 0; - for (j=(INTERNAL_FPF_PRECISION-1); j>=0; j--) - Add16Bits(&carry, - &z->mantissa[j], - z->mantissa[j], - x->mantissa[j]); - } - else - { - carry = 0; - } - - /* - ** Shift the product right. Overflow bits get - ** shifted into extra_bits. We'll use it later - ** to help with the "sticky" bit. - */ - ShiftMantRight1(&carry, z->mantissa); - ShiftMantRight1(&carry, extra_bits); - } - - /* - ** Normalize - ** Note that we use a "special" normalization routine - ** because we need to use the extra bits. (These are - ** bits that may have been shifted off the bottom that - ** we want to reclaim...if we can. - */ - while ((z->mantissa[0] & 0x8000) == 0) - { - carry = 0; - ShiftMantLeft1(&carry, extra_bits); - ShiftMantLeft1(&carry, z->mantissa); - z->exp--; - } - - /* - ** Set the sticky bit if any bits set in extra bits. - */ - if (IsMantissaZero(extra_bits)) - { - z->mantissa[INTERNAL_FPF_PRECISION-1] |= 1; - } - break; - -case NAN_NAN: - choose_nan(x, y, z, 0); - break; -} - -/* -** All math done...do rounding. -*/ -RoundInternalFPF(z); -return; -} - - -/********************** -** DivideInternalFPF ** -*********************** -** Divide internal FPF number x by y. Return result in z. -*/ -static void DivideInternalFPF(InternalFPF *x, - InternalFPF *y, - InternalFPF *z) -{ -int i; -int j; -u16 carry; -u16 extra_bits[INTERNAL_FPF_PRECISION]; -InternalFPF locx; /* Local for x number */ - -/* -** As with preceding function, the following switch -** statement selects among the various possible -** operands. -*/ -switch ((x->type * IFPF_TYPE_COUNT) + y->type) -{ -case ZERO_ZERO: -case INFINITY_INFINITY: - SetInternalFPFNaN(z); - break; - -case ZERO_SUBNORMAL: -case ZERO_NORMAL: - if (IsMantissaZero(y->mantissa)) - { - SetInternalFPFNaN(z); - break; - } - -case ZERO_INFINITY: -case SUBNORMAL_INFINITY: -case NORMAL_INFINITY: - SetInternalFPFZero(z, x->sign ^ y->sign); - break; - -case SUBNORMAL_ZERO: -case NORMAL_ZERO: - if (IsMantissaZero(x->mantissa)) - { - SetInternalFPFNaN(z); - break; - } - -case INFINITY_ZERO: -case INFINITY_SUBNORMAL: -case INFINITY_NORMAL: - SetInternalFPFInfinity(z, 0); - z->sign = x->sign ^ y->sign; - break; - -case NAN_ZERO: -case NAN_SUBNORMAL: -case NAN_NORMAL: -case NAN_INFINITY: - memmove((void *)x,(void *)z,sizeof(InternalFPF)); - break; - -case ZERO_NAN: -case SUBNORMAL_NAN: -case NORMAL_NAN: -case INFINITY_NAN: - memmove((void *)y,(void *)z,sizeof(InternalFPF)); - break; - -case SUBNORMAL_SUBNORMAL: -case NORMAL_SUBNORMAL: -case SUBNORMAL_NORMAL: -case NORMAL_NORMAL: - /* - ** Make local copy of x number, since we'll be - ** altering it in the process of dividing. - */ - memmove((void *)&locx,(void *)x,sizeof(InternalFPF)); - - /* - ** Check for unnormal zero arguments - */ - if (IsMantissaZero(locx.mantissa)) - { - if (IsMantissaZero(y->mantissa)) - SetInternalFPFNaN(z); - else - SetInternalFPFZero(z, 0); - break; - } - if (IsMantissaZero(y->mantissa)) - { - SetInternalFPFInfinity(z, 0); - break; - } - - /* - ** Initialize the result - */ - z->type = x->type; - z->sign = x->sign ^ y->sign; - z->exp = x->exp - y->exp + - ((INTERNAL_FPF_PRECISION * 16 * 2)); - for (i=0; imantissa[i] = 0; - extra_bits[i] = 0; - } - - while ((z->mantissa[0] & 0x8000) == 0) - { - carry = 0; - ShiftMantLeft1(&carry, locx.mantissa); - ShiftMantLeft1(&carry, extra_bits); - - /* - ** Time to subtract yet? - */ - if (carry == 0) - for (j=0; jmantissa[j] > extra_bits[j]) - { - carry = 0; - goto no_subtract; - } - if (y->mantissa[j] < extra_bits[j]) - break; - } - /* - ** Divisor (y) <= dividend (x), subtract - */ - carry = 0; - for (j=(INTERNAL_FPF_PRECISION-1); j>=0; j--) - Sub16Bits(&carry, - &extra_bits[j], - extra_bits[j], - y->mantissa[j]); - carry = 1; /* 1 shifted into quotient */ - no_subtract: - ShiftMantLeft1(&carry, z->mantissa); - z->exp--; - } - break; - -case NAN_NAN: - choose_nan(x, y, z, 0); - break; -} - -/* -** Math complete...do rounding -*/ -RoundInternalFPF(z); -} - -/********************** -** LongToInternalFPF ** -** Int32ToInternalFPF ** -*********************** -** Convert a signed (long) 32-bit integer into an internal FPF number. -*/ -/* static void LongToInternalFPF(long mylong, */ -static void Int32ToInternalFPF(int32 mylong, - InternalFPF *dest) -{ -int i; /* Index */ -u16 myword; /* Used to hold converted stuff */ -/* -** Save the sign and get the absolute value. This will help us -** with 64-bit machines, since we use only the lower 32 -** bits just in case. (No longer necessary after we use int32.) -*/ -/* if(mylong<0L) */ -if(mylong<(int32)0) -{ dest->sign=1; - mylong=(int32)0-mylong; -} -else - dest->sign=0; -/* -** Prepare the destination floating point number -*/ -dest->type=IFPF_IS_NORMAL; -for(i=0;imantissa[i]=0; - -/* -** See if we've got a zero. If so, make the resultant FP -** number a true zero and go home. -*/ -if(mylong==0) -{ dest->type=IFPF_IS_ZERO; - dest->exp=0; - return; -} - -/* -** Not a true zero. Set the exponent to 32 (internal FPFs have -** no bias) and load the low and high words into their proper -** locations in the mantissa. Then normalize. The action of -** normalizing slides the mantissa bits into place and sets -** up the exponent properly. -*/ -dest->exp=32; -myword=(u16)((mylong >> 16) & 0xFFFFL); -dest->mantissa[0]=myword; -myword=(u16)(mylong & 0xFFFFL); -dest->mantissa[1]=myword; -normalize(dest); -return; -} - -#ifdef DEBUG -/************************ -** InternalFPFToString ** -************************* -** FOR DEBUG PURPOSES -** This routine converts an internal floating point representation -** number to a string. Used in debugging the package. -** Returns length of converted number. -** NOTE: dest must point to a buffer big enough to hold the -** result. Also, this routine does append a null (an effect -** of using the sprintf() function). It also returns -** a length count. -** NOTE: This routine returns 5 significant digits. Thats -** about all I feel safe with, given the method of -** conversion. It should be more than enough for programmers -** to determine whether the package is properly ported. -*/ -static int InternalFPFToString(char *dest, - InternalFPF *src) -{ -InternalFPF locFPFNum; /* Local for src (will be altered) */ -InternalFPF IFPF10; /* Floating-point 10 */ -InternalFPF IFPFComp; /* For doing comparisons */ -int msign; /* Holding for mantissa sign */ -int expcount; /* Exponent counter */ -int ccount; /* Character counter */ -int i,j,k; /* Index */ -u16 carryaccum; /* Carry accumulator */ -u16 mycarry; /* Local for carry */ - -/* -** Check first for the simple things...Nan, Infinity, Zero. -** If found, copy the proper string in and go home. -*/ -switch(src->type) -{ - case IFPF_IS_NAN: - memcpy(dest,"NaN",3); - return(3); - - case IFPF_IS_INFINITY: - if(src->sign==0) - memcpy(dest,"+Inf",4); - else - memcpy(dest,"-Inf",4); - return(4); - - case IFPF_IS_ZERO: - if(src->sign==0) - memcpy(dest,"+0",2); - else - memcpy(dest,"-0",2); - return(2); -} - -/* -** Move the internal number into our local holding area, since -** we'll be altering it to print it out. -*/ -memcpy((void *)&locFPFNum,(void *)src,sizeof(InternalFPF)); - -/* -** Set up a floating-point 10...which we'll use a lot in a minute. -*/ -/* LongToInternalFPF(10L,&IFPF10); */ -Int32ToInternalFPF((int32)10,&IFPF10); - -/* -** Save the mantissa sign and make it positive. -*/ -msign=src->sign; - -/* src->sign=0 */ /* bug, fixed Nov. 13, 1997 */ -(&locFPFNum)->sign=0; - -expcount=0; /* Init exponent counter */ - -/* -** See if the number is less than 10. If so, multiply -** the number repeatedly by 10 until it's not. For each -** multiplication, decrement a counter so we can keep track -** of the exponent. -*/ - -while(1) -{ AddSubInternalFPF(1,&locFPFNum,&IFPF10,&IFPFComp); - if(IFPFComp.sign==0) break; - MultiplyInternalFPF(&locFPFNum,&IFPF10,&IFPFComp); - expcount--; - memcpy((void *)&locFPFNum,(void *)&IFPFComp,sizeof(InternalFPF)); -} -/* -** Do the reverse of the above. As long as the number is -** greater than or equal to 10, divide it by 10. Increment the -** exponent counter for each multiplication. -*/ - -while(1) -{ - AddSubInternalFPF(1,&locFPFNum,&IFPF10,&IFPFComp); - if(IFPFComp.sign!=0) break; - DivideInternalFPF(&locFPFNum,&IFPF10,&IFPFComp); - expcount++; - memcpy((void *)&locFPFNum,(void *)&IFPFComp,sizeof(InternalFPF)); -} - -/* -** About time to start storing things. First, store the -** mantissa sign. -*/ -ccount=1; /* Init character counter */ -if(msign==0) - *dest++='+'; -else - *dest++='-'; - -/* -** At this point we know that the number is in the range -** 10 > n >=1. We need to "strip digits" out of the -** mantissa. We do this by treating the mantissa as -** an integer and multiplying by 10. (Not a floating-point -** 10, but an integer 10. Since this is debug code and we -** could care less about speed, we'll do it the stupid -** way and simply add the number to itself 10 times. -** Anything that makes it to the left of the implied binary point -** gets stripped off and emitted. We'll do this for -** 5 significant digits (which should be enough to -** verify things). -*/ -/* -** Re-position radix point -*/ -carryaccum=0; -while(locFPFNum.exp>0) -{ - mycarry=0; - ShiftMantLeft1(&mycarry,locFPFNum.mantissa); - carryaccum=(carryaccum<<1); - if(mycarry) carryaccum++; - locFPFNum.exp--; -} - -while(locFPFNum.exp<0) -{ - mycarry=0; - ShiftMantRight1(&mycarry,locFPFNum.mantissa); - locFPFNum.exp++; -} - -for(i=0;i<6;i++) - if(i==1) - { /* Emit decimal point */ - *dest++='.'; - ccount++; - } - else - { /* Emit a digit */ - *dest++=('0'+carryaccum); - ccount++; - - carryaccum=0; - memcpy((void *)&IFPF10, - (void *)&locFPFNum, - sizeof(InternalFPF)); - - /* Do multiply via repeated adds */ - for(j=0;j<9;j++) - { - mycarry=0; - for(k=(INTERNAL_FPF_PRECISION-1);k>=0;k--) - Add16Bits(&mycarry,&(IFPFComp.mantissa[k]), - locFPFNum.mantissa[k], - IFPF10.mantissa[k]); - carryaccum+=mycarry ? 1 : 0; - memcpy((void *)&locFPFNum, - (void *)&IFPFComp, - sizeof(InternalFPF)); - } - } - -/* -** Now move the 'E', the exponent sign, and the exponent -** into the string. -*/ -*dest++='E'; - -/* sprint is supposed to return an integer, but it caused problems on SunOS - * with the native cc. Hence we force it. - * Uwe F. Mayer - */ -ccount+=(int)sprintf(dest,"%4d",expcount); - -/* -** All done, go home. -*/ -return(ccount); - -} - -#endif diff --git a/thirdparty/nbench-byte-2.2.3/emfloat.h b/thirdparty/nbench-byte-2.2.3/emfloat.h deleted file mode 100644 index 41cc6d9a8d8..00000000000 --- a/thirdparty/nbench-byte-2.2.3/emfloat.h +++ /dev/null @@ -1,154 +0,0 @@ - -/* -** emfloat.h -** Header for emfloat.c -** -** BYTEmark (tm) -** BYTE Magazine's Native Mode benchmarks -** Rick Grehan, BYTE Magazine -** -** Create: -** Revision: 3/95 -** -** DISCLAIMER -** The source, executable, and documentation files that comprise -** the BYTEmark benchmarks are made available on an "as is" basis. -** This means that we at BYTE Magazine have made every reasonable -** effort to verify that the there are no errors in the source and -** executable code. We cannot, however, guarantee that the programs -** are error-free. Consequently, McGraw-HIll and BYTE Magazine make -** no claims in regard to the fitness of the source code, executable -** code, and documentation of the BYTEmark. -** Furthermore, BYTE Magazine, McGraw-Hill, and all employees -** of McGraw-Hill cannot be held responsible for any damages resulting -** from the use of this code or the results obtained from using -** this code. -*/ - -#include - -/* Is this a 64 bit architecture? If so, this will define LONG64 */ -/* Uwe F. Mayer 15 November 1997 */ -#include "pointer.h" - -/* -** DEFINES -*/ -#define u8 unsigned char -#define u16 unsigned short -#ifdef LONG64 -#define u32 unsigned int -#else -#define u32 unsigned long -#endif -#define uchar unsigned char -#define ulong unsigned long - -#define MAX_EXP 32767L -#define MIN_EXP (-32767L) - -#define IFPF_IS_ZERO 0 -#define IFPF_IS_SUBNORMAL 1 -#define IFPF_IS_NORMAL 2 -#define IFPF_IS_INFINITY 3 -#define IFPF_IS_NAN 4 -#define IFPF_TYPE_COUNT 5 - -#define ZERO_ZERO 0 -#define ZERO_SUBNORMAL 1 -#define ZERO_NORMAL 2 -#define ZERO_INFINITY 3 -#define ZERO_NAN 4 - -#define SUBNORMAL_ZERO 5 -#define SUBNORMAL_SUBNORMAL 6 -#define SUBNORMAL_NORMAL 7 -#define SUBNORMAL_INFINITY 8 -#define SUBNORMAL_NAN 9 - -#define NORMAL_ZERO 10 -#define NORMAL_SUBNORMAL 11 -#define NORMAL_NORMAL 12 -#define NORMAL_INFINITY 13 -#define NORMAL_NAN 14 - -#define INFINITY_ZERO 15 -#define INFINITY_SUBNORMAL 16 -#define INFINITY_NORMAL 17 -#define INFINITY_INFINITY 18 -#define INFINITY_NAN 19 - -#define NAN_ZERO 20 -#define NAN_SUBNORMAL 21 -#define NAN_NORMAL 22 -#define NAN_INFINITY 23 -#define NAN_NAN 24 -#define OPERAND_ZERO 0 -#define OPERAND_SUBNORMAL 1 -#define OPERAND_NORMAL 2 -#define OPERAND_INFINITY 3 -#define OPERAND_NAN 4 - -/* -** Following already defined in NMGLOBAL.H -** -#define INTERNAL_FPF_PRECISION 4 -*/ - -/* -** TYPEDEFS -*/ - -typedef struct -{ - u8 type; /* Indicates, NORMAL, SUBNORMAL, etc. */ - u8 sign; /* Mantissa sign */ - short exp; /* Signed exponent...no bias */ - u16 mantissa[INTERNAL_FPF_PRECISION]; -} InternalFPF; - -/* -** PROTOTYPES -*/ -void SetupCPUEmFloatArrays(InternalFPF *abase, - InternalFPF *bbase, InternalFPF *cbase, ulong arraysize); -ulong DoEmFloatIteration(InternalFPF *abase, - InternalFPF *bbase, InternalFPF *cbase, - ulong arraysize, ulong loops); -static void SetInternalFPFZero(InternalFPF *dest, - uchar sign); -static void SetInternalFPFInfinity(InternalFPF *dest, - uchar sign); -static void SetInternalFPFNaN(InternalFPF *dest); -static int IsMantissaZero(u16 *mant); -static void Add16Bits(u16 *carry,u16 *a,u16 b,u16 c); -static void Sub16Bits(u16 *borrow,u16 *a,u16 b,u16 c); -static void ShiftMantLeft1(u16 *carry,u16 *mantissa); -static void ShiftMantRight1(u16 *carry,u16 *mantissa); -static void StickyShiftRightMant(InternalFPF *ptr,int amount); -static void normalize(InternalFPF *ptr); -static void denormalize(InternalFPF *ptr,int minimum_exponent); -void RoundInternalFPF(InternalFPF *ptr); -static void choose_nan(InternalFPF *x,InternalFPF *y,InternalFPF *z, - int intel_flag); -static void AddSubInternalFPF(uchar operation,InternalFPF *x, - InternalFPF *y,InternalFPF *z); -static void MultiplyInternalFPF(InternalFPF *x,InternalFPF *y, - InternalFPF *z); -static void DivideInternalFPF(InternalFPF *x,InternalFPF *y, - InternalFPF *z); -/* static void LongToInternalFPF(long mylong, */ -static void Int32ToInternalFPF(int32 mylong, - InternalFPF *dest); -#ifdef DEBUG -static int InternalFPFToString(char *dest, - InternalFPF *src); -#endif - -/* -** EXTERNALS -*/ -extern ulong StartStopwatch(); -extern ulong StopStopwatch(ulong elapsed); -/* extern long randwc(long num); */ -extern int32 randwc(int32 num); diff --git a/thirdparty/nbench-byte-2.2.3/hardware b/thirdparty/nbench-byte-2.2.3/hardware deleted file mode 100644 index 6fb329316ac1ff5ff3b6a534b0560a499568e17d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17013 zcmcgz3zVEim9At)n8X1R77%d776~S7=FyLt%tO{Blg?yhG8vNzf+$T-Kc*Xcx|{z0 z&cj`_V=_t%BROX|d$Jx_BjOQvan(KS8dvc|h>^&;tFG>X_&^sAoh2*bkj1Fc+3&km z^>@u=@TkXQ%~aRDw{G3Kb?esS|NpA@#)sE0Sg=6ZuuwHAVx8}AZiyk?&mV-C3aN9{ za&?7zEmGo$HSi!F2F&;>#Ad`M#8ZsOWBe1qjLf6#pf=*G3i z&Vy*tZE$2OAYBjZqFzf8FG4&Q@q9$m&O>ZLwBgkTK-I#(7%AILxzz1K#NQNHmkqR` z4T}I!cZOD-C^Y{S!xxZq=~Q#eE~Hl?ZbDoRybURJXh-Y;zRck3kZu5eufgAr^akJ$ zA!YgHh&kZw2bM1(?g0KMQsNII-U*!b5`Qb=0pKePz76Svz`tVf`;i_3{xyTY0qNtw zBL;sz(kFo*F!gl-uLHjiDfO8~JPrIHQr7oZh(|uu+(H{IMen=^X$$<aV&J3lI!^)hKxMxBg;lgWIMr35Qw*xdnPRZ~D^m=%Z!pCm`!-Y5{3KHhtnV?!fP021 z2F0^Xp-G)72IvW<7$hf|V(^|~iov*b?@xB0XsO=_Rrc3kz;FE>kb3N~nXZSxF|+J5 z_@&-6%cyaV;PGc>5SCH%9P^HULvXerM-v=BEI3<|yOj861ZRtKA>s!GXUlTSiSHMj zEzGemj@JZdOLINM%Yw7Txz)sP5u7d0Z6H1>I4zJHCB9m4S|WD?@lL^Mk=!lBLxR&X zIX39{62WPqT$#8MoR-S%Ab#@KAS|QBay8=507ohz{J%Hv{n74cPmYdl&K<;<%bncQ z-14^Tb8iM*pFp`&dtZi)w~W@we$%eU-g=o*`*u^$sl)!lnQ!cS*O_CF?R|N_3A#V_ zUA!N)O?|66wD01(0PR}{=F6x3tJU<{=8uswbD_yuJaw%4KZkC>@CVD1-6vXe_aM7| z7j)cxWXU0p^^Z~5-V^V7Yt>N&jk zFqDWH>d!UvUQnCjEgNb*i>sHJtRKwII!ccfJ3|pR;Rz^0!P^49_?g{zoKe-5eeqUs zKi?^eoyl<>nW?tcCoSXD;p#b>N2)qgf1}P3thF9TkHW0S9%G;GIuTo<)K}vtXqbKR zmVH}Wk1kXYe{`z;0$c>iOFH=(602A4>$K8cro#BC-FKW)7wp*sMMS4lqSN$L{g*Q{ zqxJ8ck@~3B@lRoz*gt(AGjuj|8m<3_=Gc39y7|(*@w(308$W4Tnr~f{dm1&4){j|E zNNbsnpO{h4Pw#ixej;r5J8U~qMULcp!BY1=Ivqc`V9CDt$^LlVy9#NoC*)rwX`kOJ z=_0@R`Nex*1|#bD&VIv7=bEWfF_>et{&!j;YOs{Lw#o5RaEFFoi*qlCUW=^;P+#;S zx&Ccf104b<`2*;M-Wsi6=;|euQKQ#8XX$lr?iZq0#cE*nBDwx%OZ`LW1!o$qzgtVx z_7ch=t?BV2(9gBk!n@hs-~ENL%+%ovrasChpf8zKKWKA)f8CbqzU0vPv6cqu#I7B0fJT)c1uL_~@Klt)fk30$5zA645oq7tttxtW5 z$X+2mec!WyHHAj|C!)E_P*jT_tq*D0+7ieV?bm6dqr&~CjZuvyq~lK2pVnkqj`TY5 z_Um_@Sb_;|I)1uM(nr{gFI|Ny&wQTy@s~a>b)DvLwo2@<)*_Xi-U;^6`s;#9Im2I} z%TdSasnasX9@6EWUy8bq3XKUk=plwF*Db9*je#&)ze!6J|KTD69--f6t-w;OAvfxj zTJ{R1Ouy*5*q+?2PN^5zmLphPv6#7a&1h-UnbS8XuteH5t>spAtE&HtUepe8alnGt zSl_om&PNYmN&W(VcAuW{FF~WHzxXC{?tZ=*dx9oVtEX0MlBV60i|?Uv1UFY#;k z&Nfy5D)f_%)6bgRtuFIaMRk-brBp|%T$Oz`k&Ne+Dr#G%m@ZWk`LvoWr89+45qoh3 zw$R26?^dZ~Dwhd)+{CY|CJSm=Iy5l46$vvL-cluhsLcztRn#z_85I~pb391wRkKJQn7bjId45IC)oK2h)!D=ZGVSHzO7i--Gxe#J@%S z2gENS{u|;C5PypJYsB;M+;asYWpl3ti^?-4w{h4$EAHv|9JL(J&3wjf-i`e`(j&mJ z?UsE%pL1F6VnhaxjR&D0pBe5%^?!t?jHGk@QrLHpY3pXuL!v-erxC8HWU{}s7!PAESNu);+YwD|Hm0f%gc!THp^0yhh;9 z3cOa}V*(Ed{6m4)3H-9aae-U$JX}-j1-?q)L4o@PrdPx71s)POFYt)K|1R*`1b$B7 z%>wh;x~8@We1*Vc0{056--B%x7>Pp`q`*4`zEfa5Ie%Q>JB0p-z%_yYQ{deKzbNn? zfzQJvR#P7k_-cVaDDY~)94}AYvq1R489JtwfXZ8P3&)U1<-gbAcj?DO{&gftu>3?UJd8!9hPTlScMGiT|82llhvy93^<_PeJu2Kv zQBMn7J()#4EuFeqn0fc}2f^hzE%j>pe_hza}mqxzJ80qN#Wlv@VLOA7FgH&&WjuMz6uL&O_S9x9k_BS>7Oz=jkb_r+x6GN z(SF|l3?dk4VyLD)IUB?7pbhbs>Bki${lvnLg6RA`rkt$7=^My>h9b)`G ze|hK1@QQ0IlJvJl!m(Aco@jThr#}E!^{Z4aSrOKVW{s@q@9YmpkW(lXCqh&83 z0eLaxs&uJ3UdU*lGQNPU9%hNP+N3?7Y;&?xArh3*xHM%PN^R<>I|I!buZNiemez*(B2JA@Nm5s_vl5*%-mkM5c?spoxGP-44>#uAbsZueU zpMVs|_jY>eOxf$0C{{ZXgBaXrXH|>&9pu{vCGf!2F`oCm4u5AkLq!}Fvzeq{t<0sO zU`HyQ$r|R#yqBV|fF_d=TGxTe1^SJ5Z~|(pWYW2$Z}g3{_jU({z?T?EL(P0jOwe>a zoPc1l*b01tsV0p3#SAqZ)@1Q}aK~1{>A>Bq$$ILEt%SQZM6e5m6;1|fmu9`anoLWD zF;GZfMY=1V0q8xJJ)m>sAw%>Ae>7tF zAwdM$0*wsaP%#S%bjNG~-B!_)3N2$>wU~^$lwC@_EQZSv_W^>srRYHCt{Xi$M|`C z2jvh#wc1U^eE7_Xc_8iCEbXb%dT(x?_Est8Z67b#K8k5)6*|79rUJTl)&@N=PfUBO z=uN$>^Tl+(3jMasPNP%IX=T2gN;JAQrn^>#3G{I~H>NvR>PAkg=v!e<+jU0J!7<&z z;__KViubflNPB&JyPlP&ZDH#1%YINu+d|Ckq2KUf+gPb9a0ATwvJ&_?EU#%V zSVPL1pce>(IO~L6YUW)}JiPczV^&X~4S*8mBtFvjjV%w$_R@<5^h&-|$@@FqMIA%H z)RxF5J)iD|lD%92IMQ&Gz^{5N5apP`q7Pa*Ulcw)lI&g}kdw}MDehQ%Wwq$#@^B3h zSbK*zn+f78)s)`{&8-qiALjH#1$2QI?dItNA8#V5NygROw5nVx@#QaG|;XxN!);zTuBNpm3d$y$kt+*$!j-6nH{m+@_>UfCCk z*>t94^sZPLiJ1D)jFb#4BQMe=wfC!82H?EXi^bwv{KC&{9%mNus9vm}%!6Bb;Rud! zBy@+c-}KZ*+V*4~8zt=7*b~MAjfyBttgS2Kh(vLWJvvOfIyq^LDh+Owvl9uJ^@N1+ zV-=jN`k5U@!!U;u**f>@3G~{{{xl7xNnaV8PNxdy! zwB>ETO}dR|$H~k-OC_hBVUBvJMem|k)YuU^r?I7CO3(5rp@%(3x0PMlZl-4$G3XKx z8;C?@yQ`2aG(zNn&s1bEp_i;ff_pn0GH9x873eH5rxOFew8iG;TlYl1)2gs_OpwbS z9w>uOFpk;i-k?qNK-q~P!M0|0n_Yuy&*4UdGX^c<)NDF=cBOX8urlq8Vmv3J{R)=0 z4CBd4C2y8BIJ5Swh;VZEK(ZE15j%n4U!S+yP8N=wx1ItG~Ys34{E z)5G?ZH#zQgIFwgfC*;k9JbYMYxc<1zsk*MHC=iZv&Sp2dW76~?c3o9WgW!STt7t4l z0S$9Y3>Ik#fv8BAo$CB0SB_3P?6qk+yX9{SkIHVXi% zM<+vs-oI%PW=$8(mPfhN;2Ay;(iIE5VwMm%ga~nrJAqkon|U-Nh$kye2ys1KMI&Vr ziNS$QBiAQ3UDwyS(jp_9Nb3tbgmr8CA`ZGSzOgSF;PH*4V>c#-Mn<=e^~D0}`mMvm ziA`I_NbL%!L&L-I!8OB%ySqUj8Q8RObT~d1H(9G1S*FOk_?CgqL!)DxHuv>3GDpVZ zn@1opzIih;dRO)<(>!#3(7d57iQzR{#+)V%4UTNu9M`3`pl#efi+vJVEaE=x1J7WB z4!DLXMnzWU^?;MF&l>EUQo)9qQ`oVb&0)s}&jvRq8gO%s5_YaXcU*860B=d7yBN&A3MPoVPH%TV1$XZuB%q83}#vDO*m*;Hfq9zUKd8Pm&5Cg zL@rrO;~f_z@QF|)@R<<%O5=!lJ(k7}xHNui1}MWe>jOZTg6O8)xPkH_L%*u+l{fX*{fP>v!n0; zZJmmb;j&{dRsHd5RvSa60vJ|SX7L-H3jNn$v0?%Fyn~7Xn-? zi!=lj=i4;vbB07$wbNS!9c_J1+m*Q(3eHm5h8Gm1V%>uycFHRXJ;&M^*35!@OP~h; zAFu}#c`j74mPh3kTa=Fv)fkrPlrc2i&um8VPIf$xF9Cg6D>)I&&(%;-D--GI>F;Or zy3FDY%bPcBQ9g-a`0&jeR0-a&Me)kbzF-@aH+Vq-=arn!G4I~cL3%61$MRXH$NL6l zfGRaOFwhrTj@u0@LVUd$itww!s%SX0d^5goY)JYcIo%Rk)gBgxwqERC|7fLPgWsdB zKV~Ud17ENu@Y`o+xVMOy&RJNs3&=HIwd1-&9{DA@ zIE2b?CZ{hqsP>d!s(2vlWTJ!uke8gyr=a$@hb;NQud27VRBaR=d(`#{JD0k@&q0PIK{_YgjweOeAa-iNXIOd0uA z6rcEok7uHefNwP-%OVjTd^%P<`O$<({dk6|8OV!(Z6GhhAR^B{k&kDeUIyQCz_wn} z8OIQLUWzc!OohO(8n9b0P?bW&aR({GGgr5Oj}B_(F(uAZ1D20xv~tL})9|rH)U zJd<`1=Nt6be#sVDgzhqYw98@e9R}YKW|+V_8SX)(Jod>RoK@rfGFul&fxHg`wtT!3 za1Z#b443Z#hmXe^4}i~UMo{MO9lnF$JNOEG|LE}XEZu|PW1rhV9T-1{$i84ZcqWkd z;2sA|KVTpa^*D^kb};gS!x6W!hK_`%_l2MGEZ=edJ`W%H=_@v@ z?uB2&c&`J2W0vipsW>)Vd7a3NI|N%V*v<-^k4V%vDPdpC6B^ewbAHjd7RY%-V5yO*%yx&B&1-R9@2C22z0^CmA1f18IZ2nCE zY}r^<&^Uf%xg{#?X;qH`cl9|2+|D0MF@O9J`1j2GKz*MDej4%)n)?5b zcxcNQt{Ur8K0ZD}hLMvlB_;}`aXgdD9y*c4Rf9w#z9F%G z^O}wE#M=1a&yxd!sZV&~ zBkNF;QPv__4UORye0n=Rh@e?`F;TAKL$Hr)(i5tZnJjI~jAXXsVKSpC)#3m)_;>+@ zjAVKgcQOXb)gj)4POQ6eWX;B*0n{?jCFa$u?agJ_EL%?Gw%d!34& -#include -#include - -#define BUF_SIZ 1024 - -/****************** -** output_string ** -******************* -** Displays a string on the screen. Also, if the flag -** write_to_file is set, outputs the string to the output file. -** Note, this routine presumes that you've included a carriage -** return at the end of the buffer. -*/ -static void output_string(const char *buffer, const int write_to_file, - FILE *global_ofile){ - printf("%s",buffer); - if(write_to_file!=0) - fprintf(global_ofile,"%s",buffer); - return; -} - - -/****************** -** removeNewLine ** -******************* -** Removes a trailing newline character if present -*/ -static void removeNewLine(char * s) { - if(strlen(s)>0 && s[strlen(s)-1] == '\n') { - s[strlen(s)-1] = '\0'; - } -} - - -/*************** -** runCommand ** -**************** -** Run the system command through a pipe -** The pointer result must point to a pre-allocated array of at least BUF_SIZ -*/ -static void runCommand (const char *command, char *result) { - FILE * pipe; - - pipe = popen(command, "r"); - if(pipe == NULL) { - /* command failed */ - result[0] = '\0'; - } else { - if(NULL == fgets(result, BUF_SIZ, pipe)){ - /* command failed */ - result[0] = '\0'; - } - pclose(pipe); - } - removeNewLine(result); -} - - -/******************** -** readProcCpuInfo ** -********************* -** Reads and parses /proc/cpuinfo on a Linux system -** The pointers must point to pre-allocated arrays of at least BUF_SIZ -*/ -static void readProcCpuInfo (char *model, char *cache) { - FILE * info; - char * cp; - int cpus = 0; - char * buffer_end; - char buffer[BUF_SIZ]; - char vendor_id[BUF_SIZ]; - char model_name[BUF_SIZ]; - char cpu_MHz[BUF_SIZ]; - int i; - float f; - - vendor_id[0] = model_name[0] = cpu_MHz[0] = model[0] = cache[0] = '\0'; - info = fopen("/proc/cpuinfo", "r"); - if(info != NULL) { - /* command did not fail */ - while(NULL != fgets(buffer, BUF_SIZ, info)){ - buffer_end = buffer + strlen(buffer); - cp = buffer; - if(! strncmp(buffer, "processor", 9)) { - cpus++; - } else if(! strncmp(buffer, "vendor_id", 9)) { - cp+=strlen("vendor_id"); - while(cp < buffer_end && ( *cp == ' ' || *cp == ':'|| *cp == '\t')) - cp++; - if(cp1) { - if (cpus==2) { - strcpy(model, "Dual"); - } else { - sprintf(model, "%d CPU", cpus); - } - } - cp = model + strlen(model); - if(vendor_id[0] != '\0'){ - if(cp != model){ - *cp++ = ' '; - } - strcpy(cp, vendor_id); - cp += strlen(vendor_id); - } - if(model_name[0] != '\0'){ - if(cp != model){ - *cp++ = ' '; - } - strcpy(cp, model_name); - cp += strlen(model_name); - } - if(cpu_MHz[0] != '\0'){ - if(cp != model){ - *cp++ = ' '; - } - f = atof(cpu_MHz); - i = (int)(f+0.5f); - sprintf(cpu_MHz, "%dMHz", i); - strcpy(cp, cpu_MHz); - cp += strlen(cpu_MHz); - } - fclose(info); - } -} - - -/************* -** hardware ** -************** -** Runs the system command "uname -s -r" -** Reads /proc/cpuinfo if on a linux system -** Writes output -*/ -void hardware(const int write_to_file, FILE *global_ofile) { - char buffer[BUF_SIZ]; - char os[BUF_SIZ]; - char model[BUF_SIZ]; - char cache[BUF_SIZ]; - char os_command[] = "uname -s -r"; -#ifdef NO_UNAME - os[0] = '\0'; -#else - runCommand(os_command, os); -#endif - if(NULL != strstr(os, "Linux")) { - readProcCpuInfo (model, cache); - } else { - model[0] = '\0'; - cache[0] = '\0'; - } - sprintf(buffer, "CPU : %s\n", model); - output_string(buffer, write_to_file, global_ofile); - sprintf(buffer, "L2 Cache : %s\n", cache); - output_string(buffer, write_to_file, global_ofile); - sprintf(buffer, "OS : %s\n", os); - output_string(buffer, write_to_file, global_ofile); -} - - -/************************ -** main for hardware.c ** -************************* -** For testing of code only -** Should be commented out -*/ -/* -int main(int argc, char * argv[]) { - hardware(0, NULL); - return 0; -} -*/ diff --git a/thirdparty/nbench-byte-2.2.3/hardware.h b/thirdparty/nbench-byte-2.2.3/hardware.h deleted file mode 100644 index 2a07934a483..00000000000 --- a/thirdparty/nbench-byte-2.2.3/hardware.h +++ /dev/null @@ -1,2 +0,0 @@ -extern -void hardware(const int write_to_file, FILE *global_ofile); diff --git a/thirdparty/nbench-byte-2.2.3/hello.c b/thirdparty/nbench-byte-2.2.3/hello.c deleted file mode 100644 index c66448346da..00000000000 --- a/thirdparty/nbench-byte-2.2.3/hello.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -int main () {printf("hello.\n");return(0);} diff --git a/thirdparty/nbench-byte-2.2.3/misc.c b/thirdparty/nbench-byte-2.2.3/misc.c deleted file mode 100644 index a5144e46b2c..00000000000 --- a/thirdparty/nbench-byte-2.2.3/misc.c +++ /dev/null @@ -1,120 +0,0 @@ - -/* -** misc.c -** BYTEmark (tm) -** BYTE's Native Mode Benchmarks -** Rick Grehan, BYTE Magazine -** DISCLAIMER -** The source, executable, and documentation files that comprise -** the BYTEmark benchmarks are made available on an "as is" basis. -** This means that we at BYTE Magazine have made every reasonable -** effort to verify that the there are no errors in the source and -** executable code. We cannot, however, guarantee that the programs -** are error-free. Consequently, McGraw-HIll and BYTE Magazine make -** no claims in regard to the fitness of the source code, executable -** code, and documentation of the BYTEmark. -** Furthermore, BYTE Magazine, McGraw-Hill, and all employees -** of McGraw-Hill cannot be held responsible for any damages resulting -** from the use of this code or the results obtained from using -** this code. -*/ - -#include -#include "misc.h" - -/*********************************************************** -** MISCELLANEOUS BUT OTHERWISE NECESSARY ROUTINES ** -***********************************************************/ - -/**************************** -** RANDOM NUMBER GENERATOR ** -***************************** -** This is a second-order linear congruential random number -** generator. Its advantage is (of course) that it can be -** seeded and will thus produce repeatable sequences of -** random numbers. -*/ - -/**************************** -* randwc() * -***************************** -** Returns signed long random modulo num. -*/ -/* -long randwc(long num) -{ - return(randnum(0L)%num); -} -*/ -/* -** Returns signed 32-bit random modulo num. -*/ -int32 randwc(int32 num) -{ - return(randnum((int32)0)%num); -} - -/*************************** -** abs_randwc() ** -**************************** -** Same as randwc(), only this routine returns only -** positive numbers. -*/ -/* -unsigned long abs_randwc(unsigned long num) -{ -long temp; - -temp=randwc(num); -if(temp<0) temp=0L-temp; - -return((unsigned long)temp); -} -*/ -u32 abs_randwc(u32 num) -{ -int32 temp; /* Temporary storage */ - -temp=randwc(num); -if(temp<0) temp=(int32)0-temp; - -return((u32)temp); -} - -/**************************** -* randnum() * -***************************** -** Second order linear congruential generator. -** Constants suggested by J. G. Skellam. -** If val==0, returns next member of sequence. -** val!=0, restart generator. -*/ -/* -long randnum(long lngval) -{ - register long interm; - static long randw[2] = { 13L , 117L }; - - if (lngval!=0L) - { randw[0]=13L; randw[1]=117L; } - - interm=(randw[0]*254754L+randw[1]*529562L)%999563L; - randw[1]=randw[0]; - randw[0]=interm; - return(interm); -} -*/ -int32 randnum(int32 lngval) -{ - register int32 interm; - static int32 randw[2] = { (int32)13 , (int32)117 }; - - if (lngval!=(int32)0) - { randw[0]=(int32)13; randw[1]=(int32)117; } - - interm=(randw[0]*(int32)254754+randw[1]*(int32)529562)%(int32)999563; - randw[1]=randw[0]; - randw[0]=interm; - return(interm); -} - diff --git a/thirdparty/nbench-byte-2.2.3/misc.h b/thirdparty/nbench-byte-2.2.3/misc.h deleted file mode 100644 index 0f9bc13c900..00000000000 --- a/thirdparty/nbench-byte-2.2.3/misc.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -** misc.h -** Header for misc.c -** BYTEmark (tm) -** BYTE's Native Mode Benchmarks -** Rick Grehan, BYTE Magazine -** -** Creation: -** Revision: 3/95 -** -** DISCLAIMER -** The source, executable, and documentation files that comprise -** the BYTEmark benchmarks are made available on an "as is" basis. -** This means that we at BYTE Magazine have made every reasonable -** effort to verify that the there are no errors in the source and -** executable code. We cannot, however, guarantee that the programs -** are error-free. Consequently, McGraw-HIll and BYTE Magazine make -** no claims in regard to the fitness of the source code, executable -** code, and documentation of the BYTEmark. -** Furthermore, BYTE Magazine, McGraw-Hill, and all employees -** of McGraw-Hill cannot be held responsible for any damages resulting -** from the use of this code or the results obtained from using -** this code. -*/ - -/************************ -** FUNCTION PROTOTYPES ** -************************/ - -/* -long randwc(long num); -unsigned long abs_randwc(unsigned long num); -long randnum(long lngval); -*/ - -#include "nmglobal.h" -int32 randwc(int32 num); -u32 abs_randwc(u32 num); -int32 randnum(int32 lngval); - - diff --git a/thirdparty/nbench-byte-2.2.3/nbench0.c b/thirdparty/nbench-byte-2.2.3/nbench0.c deleted file mode 100644 index 922b6183c19..00000000000 --- a/thirdparty/nbench-byte-2.2.3/nbench0.c +++ /dev/null @@ -1,1190 +0,0 @@ - -/* -** nbench0.c -*/ - -/******************************************* -** BYTEmark (tm) ** -** BYTE MAGAZINE'S NATIVE MODE BENCHMARKS ** -** FOR CPU/FPU ** -** ver 2.0 ** -** Rick Grehan, BYTE Magazine ** -******************************************** -** NOTE: These benchmarks do NOT check for the presence -** of an FPU. You have to find that out manually. -** -** REVISION HISTORY FOR BENCHMARKS -** 9/94 -- First beta. --RG -** 12/94 -- Bug discovered in some of the integer routines -** (IDEA, Huffman,...). Routines were not accurately counting -** the number of loops. Fixed. --RG (Thanks to Steve A.) -** 12/94 -- Added routines to calculate and display index -** values. Indexes based on DELL XPS 90 (90 MHz Pentium). -** 1/95 -- Added Mac time manager routines for more accurate -** timing on Macintosh (said to be good to 20 usecs) -- RG -** 1/95 -- Re-did all the #defines so they made more -** sense. See NMGLOBAL.H -- RG -** 3/95 -- Fixed memory leak in LU decomposition. Did not -** invalidate previous results, just made it easier to run.--RG -** 3/95 -- Added TOOLHELP.DLL timing routine to Windows timer. --RG -** 10/95 -- Added memory array & alignment; moved memory -** allocation out of LU Decomposition -- RG -** -** DISCLAIMER -** The source, executable, and documentation files that comprise -** the BYTEmark benchmarks are made available on an "as is" basis. -** This means that we at BYTE Magazine have made every reasonable -** effort to verify that the there are no errors in the source and -** executable code. We cannot, however, guarantee that the programs -** are error-free. Consequently, McGraw-HIll and BYTE Magazine make -** no claims in regard to the fitness of the source code, executable -** code, and documentation of the BYTEmark. -** Furthermore, BYTE Magazine, McGraw-Hill, and all employees -** of McGraw-Hill cannot be held responsible for any damages resulting -** from the use of this code or the results obtained from using -** this code. -*/ - -#include -#include -#include -#include -#include -#include -#include "nmglobal.h" -#include "nbench0.h" -#include "hardware.h" - -/************* -**** main **** -*************/ -#ifdef MAC -void main(void) -#else -int main(int argc, char *argv[]) -#endif -{ -int i; /* Index */ -time_t time_and_date; /* Self-explanatory */ -struct tm *loctime; -double bmean; /* Benchmark mean */ -double bstdev; /* Benchmark stdev */ -double lx_memindex; /* Linux memory index (mainly integer operations)*/ -double lx_intindex; /* Linux integer index */ -double lx_fpindex; /* Linux floating-point index */ -double intindex; /* Integer index */ -double fpindex; /* Floating-point index */ -ulong bnumrun; /* # of runs */ - -#ifdef MAC - MaxApplZone(); -#endif - -#ifdef MACTIMEMGR -/* Set up high res timer */ -MacHSTdelay=600*1000*1000; /* Delay is 10 minutes */ - -memset((char *)&myTMTask,0,sizeof(TMTask)); - -/* Prime and remove the task, calculating overhead */ -PrimeTime((QElemPtr)&myTMTask,-MacHSTdelay); -RmvTime((QElemPtr)&myTMTask); -MacHSTohead=MacHSTdelay+myTMTask.tmCount; -#endif - -#ifdef WIN31TIMER -/* Set up the size of the timer info structure */ -win31tinfo.dwSize=(DWORD)sizeof(TIMERINFO); -/* Load library */ -if((hThlp=LoadLibrary("TOOLHELP.DLL"))<32) -{ printf("Error loading TOOLHELP\n"); - exit(0); -} -if(!(lpfn=GetProcAddress(hThlp,"TimerCount"))) -{ printf("TOOLHELP error\n"); - exit(0); -} -#endif - -/* -** Set global parameters to default. -*/ -global_min_ticks=MINIMUM_TICKS; -global_min_seconds=MINIMUM_SECONDS; -global_allstats=0; -global_custrun=0; -global_align=8; -write_to_file=0; -lx_memindex=(double)1.0; /* set for geometric mean computations */ -lx_intindex=(double)1.0; -lx_fpindex=(double)1.0; -intindex=(double)1.0; -fpindex=(double)1.0; -mem_array_ents=0; /* Nothing in mem array */ - -/* -** We presume all tests will be run unless told -** otherwise -*/ -for(i=0;i1) - for(i=1;i(double)1e-100){ - /* avoid division by zero */ - sprintf(buffer," Relative standard deviation: %g %%\n", - (double)100*bstdev/bmean); - output_string(buffer); - } - sprintf(buffer," Number of runs: %lu\n",bnumrun); - output_string(buffer); - show_stats(i); - sprintf(buffer,"Done with %s\n\n",ftestnames[i]); - output_string(buffer); - } - } -} -/* printf("...done...\n"); */ - -/* -** Output the total indexes -*/ -if(global_custrun==0) -{ - sprintf(buffer,"%d\n", - (int)(pow(intindex,(double).142857)*30.0)); - output_string(buffer); -/* - output_string("==========================ORIGINAL BYTEMARK RESULTS==========================\n"); - sprintf(buffer,"INTEGER INDEX : %.3f\n", - pow(intindex,(double).142857)); - output_string(buffer); - sprintf(buffer,"FLOATING-POINT INDEX: %.3f\n", - pow(fpindex,(double).33333)); - output_string(buffer); - output_string("Baseline (MSDOS*) : Pentium* 90, 256 KB L2-cache, Watcom* compiler 10.0\n"); -#ifdef LINUX - output_string("==============================LINUX DATA BELOW===============================\n"); - hardware(write_to_file, global_ofile); -#include "sysinfoc.c" - sprintf(buffer,"MEMORY INDEX : %.3f\n", - pow(lx_memindex,(double).3333333333)); - output_string(buffer); - sprintf(buffer,"INTEGER INDEX : %.3f\n", - pow(lx_intindex,(double).25)); - output_string(buffer); - sprintf(buffer,"FLOATING-POINT INDEX: %.3f\n", - pow(lx_fpindex,(double).3333333333)); - output_string(buffer); - output_string("Baseline (LINUX) : AMD K6/233*, 512 KB L2-cache, gcc 2.7.2.3, libc-5.4.38\n"); -#endif -output_string("* Trademarks are property of their respective holder.\n"); -*/ -} - -exit(0); -} - -/************** -** parse_arg ** -*************** -** Given a pointer to a string, we assume that's an argument. -** Parse that argument and act accordingly. -** Return 0 if ok, else return -1. -*/ -static int parse_arg(char *argptr) -{ -int i; /* Index */ -FILE *cfile; /* Command file identifier */ - -/* -** First character has got to be a hyphen. -*/ -if(*argptr++!='-') return(-1); - -/* -** Convert the rest of the argument to upper case -** so there's little chance of confusion. -*/ -for(i=0;i]\n",progname); - printf(" -v = verbose\n"); - printf(" -c = input parameters thru command file \n"); - exit(0); -} - - -/***************** -** read_comfile ** -****************** -** Read the command file. Set global parameters as -** specified. This routine assumes that the command file -** is already open. -*/ -static void read_comfile(FILE *cfile) -{ -char inbuf[40]; -char *eptr; /* Offset to "=" sign */ -int i; /* Index */ - -/* -** Sit in a big loop, reading a line from the file at each -** pass. Terminate on EOF. -*/ -while(fgets(inbuf,39,cfile)!=(char *)NULL) -{ - /* Overwrite the CR character */ - if(strlen(inbuf)>0) - inbuf[strlen(inbuf)-1]='\0'; - - /* - ** Parse up to the "=" sign. If we don't find an - ** "=", then flag an error. - */ - if((eptr=strchr(inbuf,(int)'='))==(char *)NULL) - { printf("**COMMAND FILE ERROR at LINE:\n %s\n", - inbuf); - goto skipswitch; /* A GOTO!!!! */ - } - - /* - ** Insert a null where the "=" was, then convert - ** the substring to uppercase. That will enable - ** us to perform the match. - */ - *eptr++='\0'; - strtoupper((char *)&inbuf[0]); - i=MAXPARAM; - do { - if(strcmp(inbuf,paramnames[i])==0) - break; - } while(--i>=0); - - if(i<0) - { printf("**COMMAND FILE ERROR -- UNKNOWN PARAM: %s", - inbuf); - goto skipswitch; - } - - /* - ** Advance eptr to the next field...which should be - ** the value assigned to the parameter. - */ - switch(i) - { - case PF_GMTICKS: /* GLOBALMINTICKS */ - global_min_ticks=(ulong)atol(eptr); - break; - - case PF_MINSECONDS: /* MINSECONDS */ - global_min_seconds=(ulong)atol(eptr); - set_request_secs(); - break; - - case PF_ALLSTATS: /* ALLSTATS */ - global_allstats=getflag(eptr); - break; - - case PF_OUTFILE: /* OUTFILE */ - strcpy(global_ofile_name,eptr); - global_ofile=fopen(global_ofile_name,"a"); - /* - ** Open the output file. - */ - if(global_ofile==(FILE *)NULL) - { printf("**Error opening output file: %s\n", - global_ofile_name); - ErrorExit(); - } - write_to_file=-1; - break; - - case PF_CUSTOMRUN: /* CUSTOMRUN */ - global_custrun=getflag(eptr); - for(i=0;i*sdev) - { is_beaten=i; - sdev_to_beat=*sdev; - } - } - - if(is_beaten!=-1) - { scores[is_beaten]=*newscore; - return(-1); - } - return(0); - } -#endif - -/******************** -** calc_confidence ** -********************* -** Given a set of numtries scores, calculate the confidence -** half-interval. We'll also return the sample mean and sample -** standard deviation. -** NOTE: This routines presumes a confidence of 95% and -** a confidence coefficient of .95 -** returns 0 if there is an error, otherwise -1 -*/ -static int calc_confidence(double scores[], /* Array of scores */ - int num_scores, /* number of scores in array */ - double *c_half_interval, /* Confidence half-int */ - double *smean, /* Standard mean */ - double *sdev) /* Sample stand dev */ -{ -/* Here is a list of the student-t distribution up to 29 degrees of - freedom. The value at 0 is bogus, as there is no value for zero - degrees of freedom. */ -double student_t[30]={0.0 , 12.706 , 4.303 , 3.182 , 2.776 , 2.571 , - 2.447 , 2.365 , 2.306 , 2.262 , 2.228 , - 2.201 , 2.179 , 2.160 , 2.145 , 2.131 , - 2.120 , 2.110 , 2.101 , 2.093 , 2.086 , - 2.080 , 2.074 , 2.069 , 2.064 , 2.060 , - 2.056 , 2.052 , 2.048 , 2.045 }; -int i; /* Index */ -if ((num_scores<2) || (num_scores>30)) { - output_string("Internal error: calc_confidence called with an illegal number of scores\n"); - return(-1); -} -/* -** First calculate mean. -*/ -*smean=(double)0.0; -for(i=0;i -#include -/* -** Timer globals for Mac -*/ -struct TMTask myTMTask; -long MacHSTdelay,MacHSTohead; - -#endif - -/* -** Following globals used by Win 31 timing routines. -** NOTE: This requires the includes of the w31timer.asm -** file in your project!! -*/ -#ifdef WIN31TIMER -#include -#include -extern TIMERINFO win31tinfo; -extern HANDLE hThlp; -extern FARPROC lpfn; -#endif - -/* -** PROTOTYPES -*/ -static int parse_arg(char *argptr); -static void display_help(char *progname); -static void read_comfile(FILE *cfile); -static int getflag(char *cptr); -static void strtoupper(char *s); -static void set_request_secs(void); -static int bench_with_confidence(int fid, - double *mean, double *stdev, ulong *numtries); -/* -static int seek_confidence(double scores[5], - double *newscore, double *c_half_interval, - double *smean,double *sdev); -*/ -static int calc_confidence(double scores[], - int num_scores, - double *c_half_interval,double *smean, - double *sdev); -static double getscore(int fid); -static void output_string(char *buffer); -static void show_stats(int bid); - -#ifdef MAC -void UCommandLine(void); -void UParse(void); -unsigned char *UField(unsigned char *ptr); -#endif - -/* -** EXTERNAL PROTOTYPES -*/ -extern void DoNumSort(void); /* From NBENCH1 */ -extern void DoStringSort(void); -extern void DoBitops(void); -extern void DoEmFloat(void); -extern void DoFourier(void); -extern void DoAssign(void); -extern void DoIDEA(void); -extern void DoHuffman(void); -extern void DoNNET(void); -extern void DoLU(void); - -extern void ErrorExit(void); /* From SYSSPEC */ - -/* -** Array of pointers to the benchmark functions. -*/ -void (*funcpointer[])(void) = -{ DoNumSort, - DoStringSort, - DoBitops, - DoEmFloat, - DoFourier, - DoAssign, - DoIDEA, - DoHuffman, - DoNNET, - DoLU }; - - diff --git a/thirdparty/nbench-byte-2.2.3/nbench1.c b/thirdparty/nbench-byte-2.2.3/nbench1.c deleted file mode 100644 index 05c35df8c4f..00000000000 --- a/thirdparty/nbench-byte-2.2.3/nbench1.c +++ /dev/null @@ -1,4445 +0,0 @@ - -/* -** nbench1.c -*/ - -/******************************** -** BYTEmark (tm) ** -** BYTE NATIVE MODE BENCHMARKS ** -** VERSION 2 ** -** ** -** Included in this source ** -** file: ** -** Numeric Heapsort ** -** String Heapsort ** -** Bitfield test ** -** Floating point emulation ** -** Fourier coefficients ** -** Assignment algorithm ** -** IDEA Encyption ** -** Huffman compression ** -** Back prop. neural net ** -** LU Decomposition ** -** (linear equations) ** -** ---------- ** -** Rick Grehan, BYTE Magazine ** -********************************* -** -** BYTEmark (tm) -** BYTE's Native Mode Benchmarks -** Rick Grehan, BYTE Magazine -** -** Creation: -** Revision: 3/95;10/95 -** 10/95 - Removed allocation that was taking place inside -** the LU Decomposition benchmark. Though it didn't seem to -** make a difference on systems we ran it on, it nonetheless -** removes an operating system dependency that probably should -** not have been there. -** -** DISCLAIMER -** The source, executable, and documentation files that comprise -** the BYTEmark benchmarks are made available on an "as is" basis. -** This means that we at BYTE Magazine have made every reasonable -** effort to verify that the there are no errors in the source and -** executable code. We cannot, however, guarantee that the programs -** are error-free. Consequently, McGraw-HIll and BYTE Magazine make -** no claims in regard to the fitness of the source code, executable -** code, and documentation of the BYTEmark. -** Furthermore, BYTE Magazine, McGraw-Hill, and all employees -** of McGraw-Hill cannot be held responsible for any damages resulting -** from the use of this code or the results obtained from using -** this code. -*/ - -/* -** INCLUDES -*/ -#include -#include -#include -#include -#include -#include "nmglobal.h" -#include "nbench1.h" -#include "wordcat.h" - -#ifdef DEBUG -static int numsort_status=0; -static int stringsort_status=0; -#endif - -/********************* -** NUMERIC HEAPSORT ** -********************** -** This test implements a heapsort algorithm, performed on an -** array of longs. -*/ - -/************** -** DoNumSort ** -*************** -** This routine performs the CPU numeric sort test. -** NOTE: Last version incorrectly stated that the routine -** returned result in # of longword sorted per second. -** Not so; the routine returns # of iterations per sec. -*/ - -void DoNumSort(void) -{ -SortStruct *numsortstruct; /* Local pointer to global struct */ -farlong *arraybase; /* Base pointers of array */ -long accumtime; /* Accumulated time */ -double iterations; /* Iteration counter */ -char *errorcontext; /* Error context string pointer */ -int systemerror; /* For holding error codes */ - -/* -** Link to global structure -*/ -numsortstruct=&global_numsortstruct; - -/* -** Set the error context string. -*/ -errorcontext="CPU:Numeric Sort"; - -/* -** See if we need to do self adjustment code. -*/ -if(numsortstruct->adjust==0) -{ - /* - ** Self-adjustment code. The system begins by sorting 1 - ** array. If it does that in no time, then two arrays - ** are built and sorted. This process continues until - ** enough arrays are built to handle the tolerance. - */ - numsortstruct->numarrays=1; - while(1) - { - /* - ** Allocate space for arrays - */ - arraybase=(farlong *)AllocateMemory(sizeof(long) * - numsortstruct->numarrays * numsortstruct->arraysize, - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - FreeMemory((farvoid *)arraybase, - &systemerror); - ErrorExit(); - } - - /* - ** Do an iteration of the numeric sort. If the - ** elapsed time is less than or equal to the permitted - ** minimum, then allocate for more arrays and - ** try again. - */ - if(DoNumSortIteration(arraybase, - numsortstruct->arraysize, - numsortstruct->numarrays)>global_min_ticks) - break; /* We're ok...exit */ - - FreeMemory((farvoid *)arraybase,&systemerror); - if(numsortstruct->numarrays++>NUMNUMARRAYS) - { printf("CPU:NSORT -- NUMNUMARRAYS hit.\n"); - ErrorExit(); - } - } -} -else -{ /* - ** Allocate space for arrays - */ - arraybase=(farlong *)AllocateMemory(sizeof(long) * - numsortstruct->numarrays * numsortstruct->arraysize, - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - FreeMemory((farvoid *)arraybase, - &systemerror); - ErrorExit(); - } - -} -/* -** All's well if we get here. Repeatedly perform sorts until the -** accumulated elapsed time is greater than # of seconds requested. -*/ -accumtime=0L; -iterations=(double)0.0; - -do { - accumtime+=DoNumSortIteration(arraybase, - numsortstruct->arraysize, - numsortstruct->numarrays); - iterations+=(double)1.0; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. Be sure to -** show that we don't have to rerun adjustment code. -*/ -FreeMemory((farvoid *)arraybase,&systemerror); - -numsortstruct->sortspersec=iterations * - (double)numsortstruct->numarrays / TicksToFracSecs(accumtime); - -if(numsortstruct->adjust==0) - numsortstruct->adjust=1; - -#ifdef DEBUG -if (numsort_status==0) printf("Numeric sort: OK\n"); -numsort_status=0; -#endif -return; -} - -/*********************** -** DoNumSortIteration ** -************************ -** This routine executes one iteration of the numeric -** sort benchmark. It returns the number of ticks -** elapsed for the iteration. -*/ -static ulong DoNumSortIteration(farlong *arraybase, - ulong arraysize, - uint numarrays) -{ -ulong elapsed; /* Elapsed ticks */ -ulong i; -/* -** Load up the array with random numbers -*/ -LoadNumArrayWithRand(arraybase,arraysize,numarrays); - -/* -** Start the stopwatch -*/ -elapsed=StartStopwatch(); - -/* -** Execute a heap of heapsorts -*/ -for(i=0;i0; --i) - NumSift(array,i,top); - -/* -** Repeatedly extract maximum from heap and place it at the -** end of the array. When we get done, we'll have a sorted -** array. -*/ -for(i=top; i>0; --i) -{ NumSift(array,bottom,i); - temp=*array; /* Perform exchange */ - *array=*(array+i); - *(array+i)=temp; -} -return; -} - -/************ -** NumSift ** -************* -** Peforms the sift operation on a numeric array, -** constructing a heap in the array. -*/ -static void NumSift(farlong *array, /* Array of numbers */ - ulong i, /* Minimum of array */ - ulong j) /* Maximum of array */ -{ -unsigned long k; -long temp; /* Used for exchange */ - -while((i+i)<=j) -{ - k=i+i; - if(kadjust==0) -{ - /* - ** Initialize the number of arrays. - */ - strsortstruct->numarrays=1; - while(1) - { - /* - ** Allocate space for array. We'll add an extra 100 - ** bytes to protect memory as strings move around - ** (this can happen during string adjustment) - */ - arraybase=(faruchar *)AllocateMemory((strsortstruct->arraysize+100L) * - (long)strsortstruct->numarrays,&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - ErrorExit(); - } - - /* - ** Do an iteration of the string sort. If the - ** elapsed time is less than or equal to the permitted - ** minimum, then de-allocate the array, reallocate a - ** an additional array, and try again. - */ - if(DoStringSortIteration(arraybase, - strsortstruct->numarrays, - strsortstruct->arraysize)>global_min_ticks) - break; /* We're ok...exit */ - - FreeMemory((farvoid *)arraybase,&systemerror); - strsortstruct->numarrays+=1; - } -} -else -{ - /* - ** We don't have to perform self adjustment code. - ** Simply allocate the space for the array. - */ - arraybase=(faruchar *)AllocateMemory((strsortstruct->arraysize+100L) * - (long)strsortstruct->numarrays,&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - ErrorExit(); - } -} -/* -** All's well if we get here. Repeatedly perform sorts until the -** accumulated elapsed time is greater than # of seconds requested. -*/ -accumtime=0L; -iterations=(double)0.0; - -do { - accumtime+=DoStringSortIteration(arraybase, - strsortstruct->numarrays, - strsortstruct->arraysize); - iterations+=(double)strsortstruct->numarrays; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. -** Set flag to show we don't need to rerun adjustment code. -*/ -FreeMemory((farvoid *)arraybase,&systemerror); -strsortstruct->sortspersec=iterations / (double)TicksToFracSecs(accumtime); -if(strsortstruct->adjust==0) - strsortstruct->adjust=1; -#ifdef DEBUG -if (stringsort_status==0) printf("String sort: OK\n"); -stringsort_status=0; -#endif -return; -} - -/************************** -** DoStringSortIteration ** -*************************** -** This routine executes one iteration of the string -** sort benchmark. It returns the number of ticks -** Note that this routine also builds the offset pointer -** array. -*/ -static ulong DoStringSortIteration(faruchar *arraybase, - uint numarrays,ulong arraysize) -{ -farulong *optrarray; /* Offset pointer array */ -unsigned long elapsed; /* Elapsed ticks */ -unsigned long nstrings; /* # of strings in array */ -int syserror; /* System error code */ -unsigned int i; /* Index */ -farulong *tempobase; /* Temporary offset pointer base */ -faruchar *tempsbase; /* Temporary string base pointer */ - -/* -** Load up the array(s) with random numbers -*/ -optrarray=LoadStringArray(arraybase,numarrays,&nstrings,arraysize); - -/* -** Set temp base pointers...they will be modified as the -** benchmark proceeds. -*/ -tempobase=optrarray; -tempsbase=arraybase; - -/* -** Start the stopwatch -*/ -elapsed=StartStopwatch(); - -/* -** Execute heapsorts -*/ -for(i=0;i=arraysize) - { stringlength=(unsigned char)((arraysize-curroffset-1L) & - 0xFF); - fullflag=1; /* Indicates a full */ - } - - /* - ** Store length at curroffset and advance current offset. - */ - *(strarray+curroffset)=stringlength; - curroffset++; - - /* - ** Fill up the rest of the string with random bytes. - */ - for(i=0;i0; --i) - strsift(optrarray,strarray,numstrings,i,top); - -/* -** Repeatedly extract maximum from heap and place it at the -** end of the array. When we get done, we'll have a sorted -** array. -*/ -for(i=top; i>0; --i) -{ - strsift(optrarray,strarray,numstrings,0,i); - - /* temp = string[0] */ - tlen=*strarray; - MoveMemory((farvoid *)&temp[0], /* Perform exchange */ - (farvoid *)strarray, - (unsigned long)(tlen+1)); - - - /* string[0]=string[i] */ - tlen=*(strarray+*(optrarray+i)); - stradjust(optrarray,strarray,numstrings,0,tlen); - MoveMemory((farvoid *)strarray, - (farvoid *)(strarray+*(optrarray+i)), - (unsigned long)(tlen+1)); - - /* string[i]=temp */ - tlen=temp[0]; - stradjust(optrarray,strarray,numstrings,i,tlen); - MoveMemory((farvoid *)(strarray+*(optrarray+i)), - (farvoid *)&temp[0], - (unsigned long)(tlen+1)); - -} -return; -} - -/**************** -** str_is_less ** -***************** -** Pass this function: -** 1) A pointer to an array of offset pointers -** 2) A pointer to a string array -** 3) The number of elements in the string array -** 4) Offsets to two strings (a & b) -** This function returns TRUE if string a is < string b. -*/ -static int str_is_less(farulong *optrarray, /* Offset pointers */ - faruchar *strarray, /* String array */ - ulong numstrings, /* # of strings */ - ulong a, ulong b) /* Offsets */ -{ -int slen; /* String length */ - -/* -** Determine which string has the minimum length. Use that -** to call strncmp(). If they match up to that point, the -** string with the longer length wins. -*/ -slen=(int)*(strarray+*(optrarray+a)); -if(slen > (int)*(strarray+*(optrarray+b))) - slen=(int)*(strarray+*(optrarray+b)); - -slen=strncmp((char *)(strarray+*(optrarray+a)), - (char *)(strarray+*(optrarray+b)),slen); - -if(slen==0) -{ - /* - ** They match. Return true if the length of a - ** is greater than the length of b. - */ - if(*(strarray+*(optrarray+a)) > - *(strarray+*(optrarray+b))) - return(TRUE); - return(FALSE); -} - -if(slen<0) return(TRUE); /* a is strictly less than b */ - -return(FALSE); /* Only other possibility */ -} - -/************ -** strsift ** -************* -** Pass this function: -** 1) A pointer to an array of offset pointers -** 2) A pointer to a string array -** 3) The number of elements in the string array -** 4) Offset within which to sort. -** Sift the array within the bounds of those offsets (thus -** building a heap). -*/ -static void strsift(farulong *optrarray, /* Offset pointers */ - faruchar *strarray, /* String array */ - ulong numstrings, /* # of strings */ - ulong i, ulong j) /* Offsets */ -{ -unsigned long k; /* Temporaries */ -unsigned char temp[80]; -unsigned char tlen; /* For string lengths */ - - -while((i+i)<=j) -{ - k=i+i; - if(kadjust==0) -{ - bitarraybase=(farulong *)AllocateMemory(locbitopstruct->bitfieldarraysize * - sizeof(ulong),&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - ErrorExit(); - } - - /* - ** Initialize bitfield operations array to [2,30] elements - */ - locbitopstruct->bitoparraysize=30L; - - while(1) - { - /* - ** Allocate space for operations array - */ - bitoparraybase=(farulong *)AllocateMemory(locbitopstruct->bitoparraysize*2L* - sizeof(ulong), - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - FreeMemory((farvoid *)bitarraybase,&systemerror); - ErrorExit(); - } - /* - ** Do an iteration of the bitmap test. If the - ** elapsed time is less than or equal to the permitted - ** minimum, then de-allocate the array, reallocate a - ** larger version, and try again. - */ - ticks=DoBitfieldIteration(bitarraybase, - bitoparraybase, - locbitopstruct->bitoparraysize, - &nbitops); -#ifdef DEBUG -#ifdef LINUX - if (locbitopstruct->bitoparraysize==30L){ - /* this is the first loop, write a debug file */ - FILE *file; - unsigned long *running_base; /* same as farulong */ - long counter; - file=fopen("debugbit.dat","w"); - running_base=bitarraybase; - for (counter=0;counter<(long)(locbitopstruct->bitfieldarraysize);counter++){ -#ifdef LONG64 - fprintf(file,"%08X",(unsigned int)(*running_base&0xFFFFFFFFL)); - fprintf(file,"%08X",(unsigned int)((*running_base>>32)&0xFFFFFFFFL)); - if ((counter+1)%4==0) fprintf(file,"\n"); -#else - fprintf(file,"%08lX",*running_base); - if ((counter+1)%8==0) fprintf(file,"\n"); -#endif - running_base=running_base+1; - } - fclose(file); - printf("\nWrote the file debugbit.dat, you may want to compare it to debugbit.good\n"); - } -#endif -#endif - - if (ticks>global_min_ticks) break; /* We're ok...exit */ - - FreeMemory((farvoid *)bitoparraybase,&systemerror); - locbitopstruct->bitoparraysize+=100L; - } -} -else -{ - /* - ** Don't need to do self adjustment, just allocate - ** the array space. - */ - bitarraybase=(farulong *)AllocateMemory(locbitopstruct->bitfieldarraysize * - sizeof(ulong),&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - ErrorExit(); - } - bitoparraybase=(farulong *)AllocateMemory(locbitopstruct->bitoparraysize*2L* - sizeof(ulong), - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - FreeMemory((farvoid *)bitarraybase,&systemerror); - ErrorExit(); - } -} - -/* -** All's well if we get here. Repeatedly perform bitops until the -** accumulated elapsed time is greater than # of seconds requested. -*/ -accumtime=0L; -iterations=(double)0.0; -do { - accumtime+=DoBitfieldIteration(bitarraybase, - bitoparraybase, - locbitopstruct->bitoparraysize,&nbitops); - iterations+=(double)nbitops; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. -** Also, set adjustment flag to show that we don't have -** to do self adjusting in the future. -*/ -FreeMemory((farvoid *)bitarraybase,&systemerror); -FreeMemory((farvoid *)bitoparraybase,&systemerror); -locbitopstruct->bitopspersec=iterations /TicksToFracSecs(accumtime); -if(locbitopstruct->adjust==0) - locbitopstruct->adjust=1; - -return; -} - -/************************ -** DoBitfieldIteration ** -************************* -** Perform a single iteration of the bitfield benchmark. -** Return the # of ticks accumulated by the operation. -*/ -static ulong DoBitfieldIteration(farulong *bitarraybase, - farulong *bitoparraybase, - long bitoparraysize, - ulong *nbitops) -{ -long i; /* Index */ -ulong bitoffset; /* Offset into bitmap */ -ulong elapsed; /* Time to execute */ -/* -** Clear # bitops counter -*/ -*nbitops=0L; - -/* -** Construct a set of bitmap offsets and run lengths. -** The offset can be any random number from 0 to the -** size of the bitmap (in bits). The run length can -** be any random number from 1 to the number of bits -** between the offset and the end of the bitmap. -** Note that the bitmap has 8192 * 32 bits in it. -** (262,144 bits) -*/ -/* -** Reset random number generator so things repeat. -** Also reset the bit array we work on. -** added by Uwe F. Mayer -*/ -randnum((int32)13); -for (i=0;i>6; /* Index is number /64 */ - bitnumb=bit_addr % 64; /* Bit number in word */ -#else - bindex=bit_addr>>5; /* Index is number /32 */ - bitnumb=bit_addr % 32; /* bit number in word */ -#endif - if(val) - bitmap[bindex]|=(1L<>6; /* Index is number /64 */ - bitnumb=bit_addr % 64; /* Bit number in longword */ -#else - bindex=bit_addr>>5; /* Index is number /32 */ - bitnumb=bit_addr % 32; /* Bit number in longword */ -#endif - bitmap[bindex]^=(1L<arraysize*sizeof(InternalFPF), - &systemerror); -if(systemerror) -{ ReportError(errorcontext,systemerror); - ErrorExit(); -} - -bbase=(InternalFPF *)AllocateMemory(locemfloatstruct->arraysize*sizeof(InternalFPF), - &systemerror); -if(systemerror) -{ ReportError(errorcontext,systemerror); - FreeMemory((farvoid *)abase,&systemerror); - ErrorExit(); -} - -cbase=(InternalFPF *)AllocateMemory(locemfloatstruct->arraysize*sizeof(InternalFPF), - &systemerror); -if(systemerror) -{ ReportError(errorcontext,systemerror); - FreeMemory((farvoid *)abase,&systemerror); - FreeMemory((farvoid *)bbase,&systemerror); - ErrorExit(); -} - -/* -** Set up the arrays -*/ -SetupCPUEmFloatArrays(abase,bbase,cbase,locemfloatstruct->arraysize); - -/* -** See if we need to do self-adjusting code. -*/ -if(locemfloatstruct->adjust==0) -{ - locemfloatstruct->loops=0; - - /* - ** Do an iteration of the tests. If the elapsed time is - ** less than minimum, increase the loop count and try - ** again. - */ - for(loops=1;loopsarraysize, - loops); - if(tickcount>global_min_ticks) - { locemfloatstruct->loops=loops; - break; - } - } -} - -/* -** Verify that selft adjustment code worked. -*/ -if(locemfloatstruct->loops==0) -{ printf("CPU:EMFPU -- CMPUEMFLOATLOOPMAX limit hit\n"); - FreeMemory((farvoid *)abase,&systemerror); - FreeMemory((farvoid *)bbase,&systemerror); - FreeMemory((farvoid *)cbase,&systemerror); - ErrorExit(); -} - -/* -** All's well if we get here. Repeatedly perform floating -** tests until the accumulated time is greater than the -** # of seconds requested. -** Each iteration performs arraysize * 3 operations. -*/ -accumtime=0L; -iterations=(double)0.0; -do { - accumtime+=DoEmFloatIteration(abase,bbase,cbase, - locemfloatstruct->arraysize, - locemfloatstruct->loops); - iterations+=(double)1.0; -} while(TicksToSecs(accumtime)request_secs); - - -/* -** Clean up, calculate results, and go home. -** Also, indicate that adjustment is done. -*/ -FreeMemory((farvoid *)abase,&systemerror); -FreeMemory((farvoid *)bbase,&systemerror); -FreeMemory((farvoid *)cbase,&systemerror); - -locemfloatstruct->emflops=(iterations*(double)locemfloatstruct->loops)/ - (double)TicksToFracSecs(accumtime); -if(locemfloatstruct->adjust==0) - locemfloatstruct->adjust=1; - -#ifdef DEBUG -printf("----------------------------------------------------------------------------\n"); -#endif -return; -} - -/************************* -** FOURIER COEFFICIENTS ** -*************************/ - -/************** -** DoFourier ** -*************** -** Perform the transcendental/trigonometric portion of the -** benchmark. This benchmark calculates the first n -** fourier coefficients of the function (x+1)^x defined -** on the interval 0,2. -*/ -void DoFourier(void) -{ -FourierStruct *locfourierstruct; /* Local fourier struct */ -fardouble *abase; /* Base of A[] coefficients array */ -fardouble *bbase; /* Base of B[] coefficients array */ -unsigned long accumtime; /* Accumulated time in ticks */ -double iterations; /* # of iterations */ -char *errorcontext; /* Error context string pointer */ -int systemerror; /* For error code */ - -/* -** Link to global structure -*/ -locfourierstruct=&global_fourierstruct; - -/* -** Set error context string -*/ -errorcontext="FPU:Transcendental"; - -/* -** See if we need to do self-adjustment code. -*/ -if(locfourierstruct->adjust==0) -{ - locfourierstruct->arraysize=100L; /* Start at 100 elements */ - while(1) - { - - abase=(fardouble *)AllocateMemory(locfourierstruct->arraysize*sizeof(double), - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - ErrorExit(); - } - - bbase=(fardouble *)AllocateMemory(locfourierstruct->arraysize*sizeof(double), - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - FreeMemory((void *)abase,&systemerror); - ErrorExit(); - } - /* - ** Do an iteration of the tests. If the elapsed time is - ** less than or equal to the permitted minimum, re-allocate - ** larger arrays and try again. - */ - if(DoFPUTransIteration(abase,bbase, - locfourierstruct->arraysize)>global_min_ticks) - break; /* We're ok...exit */ - - /* - ** Make bigger arrays and try again. - */ - FreeMemory((farvoid *)abase,&systemerror); - FreeMemory((farvoid *)bbase,&systemerror); - locfourierstruct->arraysize+=50L; - } -} -else -{ /* - ** Don't need self-adjustment. Just allocate the - ** arrays, and go. - */ - abase=(fardouble *)AllocateMemory(locfourierstruct->arraysize*sizeof(double), - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - ErrorExit(); - } - - bbase=(fardouble *)AllocateMemory(locfourierstruct->arraysize*sizeof(double), - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - FreeMemory((void *)abase,&systemerror); - ErrorExit(); - } -} -/* -** All's well if we get here. Repeatedly perform integration -** tests until the accumulated time is greater than the -** # of seconds requested. -*/ -accumtime=0L; -iterations=(double)0.0; -do { - accumtime+=DoFPUTransIteration(abase,bbase,locfourierstruct->arraysize); - iterations+=(double)locfourierstruct->arraysize*(double)2.0-(double)1.0; -} while(TicksToSecs(accumtime)request_secs); - - -/* -** Clean up, calculate results, and go home. -** Also set adjustment flag to indicate no adjust code needed. -*/ -FreeMemory((farvoid *)abase,&systemerror); -FreeMemory((farvoid *)bbase,&systemerror); - -locfourierstruct->fflops=iterations/(double)TicksToFracSecs(accumtime); - -if(locfourierstruct->adjust==0) - locfourierstruct->adjust=1; - -return; -} - -/************************ -** DoFPUTransIteration ** -************************* -** Perform an iteration of the FPU Transcendental/trigonometric -** benchmark. Here, an iteration consists of calculating the -** first n fourier coefficients of the function (x+1)^x on -** the interval 0,2. n is given by arraysize. -** NOTE: The # of integration steps is fixed at -** 200. -*/ -static ulong DoFPUTransIteration(fardouble *abase, /* A coeffs. */ - fardouble *bbase, /* B coeffs. */ - ulong arraysize) /* # of coeffs */ -{ -double omega; /* Fundamental frequency */ -unsigned long i; /* Index */ -unsigned long elapsed; /* Elapsed time */ - -/* -** Start the stopwatch -*/ -elapsed=StartStopwatch(); - -/* -** Calculate the fourier series. Begin by -** calculating A[0]. -*/ - -*abase=TrapezoidIntegrate((double)0.0, - (double)2.0, - 200, - (double)0.0, /* No omega * n needed */ - 0 )/(double)2.0; - -/* -** Calculate the fundamental frequency. -** ( 2 * pi ) / period...and since the period -** is 2, omega is simply pi. -*/ -omega=(double)3.1415926535897932; - -for(i=1;iadjust==0) -{ - /* - ** Self-adjustment code. The system begins by working on 1 - ** array. If it does that in no time, then two arrays - ** are built. This process continues until - ** enough arrays are built to handle the tolerance. - */ - locassignstruct->numarrays=1; - while(1) - { - /* - ** Allocate space for arrays - */ - arraybase=(farlong *) AllocateMemory(sizeof(long)* - ASSIGNROWS*ASSIGNCOLS*locassignstruct->numarrays, - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - FreeMemory((farvoid *)arraybase, - &systemerror); - ErrorExit(); - } - - /* - ** Do an iteration of the assignment alg. If the - ** elapsed time is less than or equal to the permitted - ** minimum, then allocate for more arrays and - ** try again. - */ - if(DoAssignIteration(arraybase, - locassignstruct->numarrays)>global_min_ticks) - break; /* We're ok...exit */ - - FreeMemory((farvoid *)arraybase, &systemerror); - locassignstruct->numarrays++; - } -} -else -{ /* - ** Allocate space for arrays - */ - arraybase=(farlong *)AllocateMemory(sizeof(long)* - ASSIGNROWS*ASSIGNCOLS*locassignstruct->numarrays, - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - FreeMemory((farvoid *)arraybase, - &systemerror); - ErrorExit(); - } -} - -/* -** All's well if we get here. Do the tests. -*/ -accumtime=0L; -iterations=(double)0.0; - -do { - accumtime+=DoAssignIteration(arraybase, - locassignstruct->numarrays); - iterations+=(double)1.0; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. Be sure to -** show that we don't have to rerun adjustment code. -*/ -FreeMemory((farvoid *)arraybase,&systemerror); - -locassignstruct->iterspersec=iterations * - (double)locassignstruct->numarrays / TicksToFracSecs(accumtime); - -if(locassignstruct->adjust==0) - locassignstruct->adjust=1; - -return; - -} - -/********************** -** DoAssignIteration ** -*********************** -** This routine executes one iteration of the assignment test. -** It returns the number of ticks elapsed in the iteration. -*/ -static ulong DoAssignIteration(farlong *arraybase, - ulong numarrays) -{ -longptr abase; /* local pointer */ -ulong elapsed; /* Elapsed ticks */ -ulong i; - -/* -** Set up local pointer -*/ -abase.ptrs.p=arraybase; - -/* -** Load up the arrays with a random table. -*/ -LoadAssignArrayWithRand(arraybase,numarrays); - -/* -** Start the stopwatch -*/ -elapsed=StartStopwatch(); - -/* -** Execute assignment algorithms -*/ -for(i=0;i1) - for(i=1;i>encrypt>> crypt1 >>decrypt>> plain2. -** So, plain1 and plain2 should match. -** Also, fill up plain1 with sample text. -*/ -plain1=(faruchar *)AllocateMemory(locideastruct->arraysize,&systemerror); -if(systemerror) -{ - ReportError(errorcontext,systemerror); - ErrorExit(); -} - -crypt1=(faruchar *)AllocateMemory(locideastruct->arraysize,&systemerror); -if(systemerror) -{ - ReportError(errorcontext,systemerror); - FreeMemory((farvoid *)plain1,&systemerror); - ErrorExit(); -} - -plain2=(faruchar *)AllocateMemory(locideastruct->arraysize,&systemerror); -if(systemerror) -{ - ReportError(errorcontext,systemerror); - FreeMemory((farvoid *)plain1,&systemerror); - FreeMemory((farvoid *)crypt1,&systemerror); - ErrorExit(); -} -/* -** Note that we build the "plaintext" by simply loading -** the array up with random numbers. -*/ -for(i=0;iarraysize;i++) - plain1[i]=(uchar)(abs_randwc(255) & 0xFF); - -/* -** See if we need to perform self adjustment loop. -*/ -if(locideastruct->adjust==0) -{ - /* - ** Do self-adjustment. This involves initializing the - ** # of loops and increasing the loop count until we - ** get a number of loops that we can use. - */ - for(locideastruct->loops=100L; - locideastruct->loopsloops+=10L) - if(DoIDEAIteration(plain1,crypt1,plain2, - locideastruct->arraysize, - locideastruct->loops, - Z,DK)>global_min_ticks) break; -} - -/* -** All's well if we get here. Do the test. -*/ -accumtime=0L; -iterations=(double)0.0; - -do { - accumtime+=DoIDEAIteration(plain1,crypt1,plain2, - locideastruct->arraysize, - locideastruct->loops,Z,DK); - iterations+=(double)locideastruct->loops; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. Be sure to -** show that we don't have to rerun adjustment code. -*/ -FreeMemory((farvoid *)plain1,&systemerror); -FreeMemory((farvoid *)crypt1,&systemerror); -FreeMemory((farvoid *)plain2,&systemerror); -locideastruct->iterspersec=iterations / TicksToFracSecs(accumtime); - -if(locideastruct->adjust==0) - locideastruct->adjust=1; - -return; - -} - -/******************** -** DoIDEAIteration ** -********************* -** Execute a single iteration of the IDEA encryption algorithm. -** Actually, a single iteration is one encryption and one -** decryption. -*/ -static ulong DoIDEAIteration(faruchar *plain1, - faruchar *crypt1, - faruchar *plain2, - ulong arraysize, - ulong nloops, - IDEAkey Z, - IDEAkey DK) -{ -register ulong i; -register ulong j; -ulong elapsed; -#ifdef DEBUG -int status=0; -#endif - -/* -** Start the stopwatch. -*/ -elapsed=StartStopwatch(); - -/* -** Do everything for nloops. -*/ -for(i=0;i>16); - return(b-a+(b> 7); - Z+=i&8; - i&=7; -} -return; -} - -/**************** -** de_key_idea ** -***************** -** Compute IDEA decryption subkeys DK from encryption -** subkeys Z. -*/ -static void de_key_idea(IDEAkey Z, IDEAkey DK) -{ -IDEAkey TT; -int j; -u16 t1, t2, t3; -u16 *p; -p=(u16 *)(TT+KEYLEN); - -t1=inv(*Z++); -t2=-*Z++; -t3=-*Z++; -*--p=inv(*Z++); -*--p=t3; -*--p=t2; -*--p=t1; - -for(j=1;jarraysize,&systemerror); -if(systemerror) -{ ReportError(errorcontext,systemerror); - ErrorExit(); -} -comparray=(farchar *)AllocateMemory(lochuffstruct->arraysize,&systemerror); -if(systemerror) -{ ReportError(errorcontext,systemerror); - FreeMemory(plaintext,&systemerror); - ErrorExit(); -} -decomparray=(farchar *)AllocateMemory(lochuffstruct->arraysize,&systemerror); -if(systemerror) -{ ReportError(errorcontext,systemerror); - FreeMemory(plaintext,&systemerror); - FreeMemory(comparray,&systemerror); - ErrorExit(); -} - -hufftree=(huff_node *)AllocateMemory(sizeof(huff_node) * 512, - &systemerror); -if(systemerror) -{ ReportError(errorcontext,systemerror); - FreeMemory(plaintext,&systemerror); - FreeMemory(comparray,&systemerror); - FreeMemory(decomparray,&systemerror); - ErrorExit(); -} - -/* -** Build the plaintext buffer. Since we want this to -** actually be able to compress, we'll use the -** wordcatalog to build the plaintext stuff. -*/ -/* -** Reset random number generator so things repeat. -** added by Uwe F. Mayer -*/ -randnum((int32)13); -create_text_block(plaintext,lochuffstruct->arraysize-1,(ushort)500); -plaintext[lochuffstruct->arraysize-1L]='\0'; -plaintextlen=lochuffstruct->arraysize; - -/* -** See if we need to perform self adjustment loop. -*/ -if(lochuffstruct->adjust==0) -{ - /* - ** Do self-adjustment. This involves initializing the - ** # of loops and increasing the loop count until we - ** get a number of loops that we can use. - */ - for(lochuffstruct->loops=100L; - lochuffstruct->loopsloops+=10L) - if(DoHuffIteration(plaintext, - comparray, - decomparray, - lochuffstruct->arraysize, - lochuffstruct->loops, - hufftree)>global_min_ticks) break; -} - -/* -** All's well if we get here. Do the test. -*/ -accumtime=0L; -iterations=(double)0.0; - -do { - accumtime+=DoHuffIteration(plaintext, - comparray, - decomparray, - lochuffstruct->arraysize, - lochuffstruct->loops, - hufftree); - iterations+=(double)lochuffstruct->loops; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. Be sure to -** show that we don't have to rerun adjustment code. -*/ -FreeMemory((farvoid *)plaintext,&systemerror); -FreeMemory((farvoid *)comparray,&systemerror); -FreeMemory((farvoid *)decomparray,&systemerror); -FreeMemory((farvoid *)hufftree,&systemerror); -lochuffstruct->iterspersec=iterations / TicksToFracSecs(accumtime); - -if(lochuffstruct->adjust==0) - lochuffstruct->adjust=1; - -} - -/********************* -** create_text_line ** -********************** -** Create a random line of text, stored at *dt. The line may be -** no more than nchars long. -*/ -static void create_text_line(farchar *dt, - long nchars) -{ -long charssofar; /* # of characters so far */ -long tomove; /* # of characters to move */ -char myword[40]; /* Local buffer for words */ -farchar *wordptr; /* Pointer to word from catalog */ - -charssofar=0; - -do { -/* -** Grab a random word from the wordcatalog -*/ -/* wordptr=wordcatarray[abs_randwc((long)WORDCATSIZE)];*/ -wordptr=wordcatarray[abs_randwc((int32)WORDCATSIZE)]; -MoveMemory((farvoid *)myword, - (farvoid *)wordptr, - (unsigned long)strlen(wordptr)+1); - -/* -** Append a blank. -*/ -tomove=strlen(myword)+1; -myword[tomove-1]=' '; - -/* -** See how long it is. If its length+charssofar > nchars, we have -** to trim it. -*/ -if((tomove+charssofar)>nchars) - tomove=nchars-charssofar; -/* -** Attach the word to the current line. Increment counter. -*/ -MoveMemory((farvoid *)dt,(farvoid *)myword,(unsigned long)tomove); -charssofar+=tomove; -dt+=tomove; - -/* -** If we're done, bail out. Otherwise, go get another word. -*/ -} while(charssofartblen) - linelen=tblen-bytessofar; - -if(linelen>1) -{ - create_text_line(tb,linelen); -} -tb+=linelen-1; /* Add the carriage return */ -*tb++='\n'; - -bytessofar+=linelen; - -} while(bytessofar>3; -bitnumb=bitoffset % 8; - -/* -** Set or clear -*/ -if(bitchar=='1') - comparray[byteoffset]|=(1<>3; -bitnumb=bitoffset % 8; - -/* -** Fetch -*/ -return((1<adjust==0) -{ - /* - ** Do self-adjustment. This involves initializing the - ** # of loops and increasing the loop count until we - ** get a number of loops that we can use. - */ - for(locnnetstruct->loops=1L; - locnnetstruct->loopsloops++) - { /*randnum(3L); */ - randnum((int32)3); - if(DoNNetIteration(locnnetstruct->loops) - >global_min_ticks) break; - } -} - -/* -** All's well if we get here. Do the test. -*/ -accumtime=0L; -iterations=(double)0.0; - -do { - /* randnum(3L); */ /* Gotta do this for Neural Net */ - randnum((int32)3); /* Gotta do this for Neural Net */ - accumtime+=DoNNetIteration(locnnetstruct->loops); - iterations+=(double)locnnetstruct->loops; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. Be sure to -** show that we don't have to rerun adjustment code. -*/ -locnnetstruct->iterspersec=iterations / TicksToFracSecs(accumtime); - -if(locnnetstruct->adjust==0) - locnnetstruct->adjust=1; - - -return; -} - -/******************** -** DoNNetIteration ** -********************* -** Do a single iteration of the neural net benchmark. -** By iteration, we mean a "learning" pass. -*/ -static ulong DoNNetIteration(ulong nloops) -{ -ulong elapsed; /* Elapsed time */ -int patt; - -/* -** Run nloops learning cycles. Notice that, counted with -** the learning cycle is the weight randomization and -** zeroing of changes. This should reduce clock jitter, -** since we don't have to stop and start the clock for -** each iteration. -*/ -elapsed=StartStopwatch(); -while(nloops--) -{ - randomize_wts(); - zero_changes(); - iteration_count=1; - learned = F; - numpasses = 0; - while (learned == F) - { - for (patt=0; patt tot_error) - tot_error = -error; /* worst error this pattern */ - } - else - { - sum += error; - if (error > tot_error) - tot_error = error; /* worst error this pattern */ - } -} -avg_out_error[patt] = sum/OUT_SIZE; -tot_out_error[patt] = tot_error; -return; -} - -/*********************** -** worst_pass_error() ** -************************ -** Find the worst and average error in the pass and save it -**/ -static void worst_pass_error() -{ -double error,sum; - -int i; - -error = 0.0; -sum = 0.0; -for (i=0; i error) error = tot_out_error[i]; - sum += avg_out_error[i]; -} -worst_error = error; -average_error = sum/numpats; -return; -} - -/******************* -** do_mid_error() ** -******************** -** Compute the error for the middle layer neurodes -** This is based on the output errors computed above. -** Note that the derivative of the sigmoid f(x) is -** f'(x) = f(x)(1 - f(x)) -** Recall that f(x) is merely the output of the middle -** layer neurode on the forward pass. -**/ -static void do_mid_error() -{ -double sum; -int neurode, i; - -for (neurode=0; neurode= STOP) result = F; - if (tot_out_error[i] >= 16.0) error = T; -} - -if (error == T) result = ERR; - - -#ifdef DEBUG -/* printf("\n Error this pass thru data: Worst: %8.3f; Average: %8.3f", - worst_error,average_error); -*/ -/* fprintf(outfile, - "\n Error this pass thru data: Worst: %8.3f; Average: %8.3f", - worst_error, average_error); */ -#endif - -return(result); -} - - -/******************* -** zero_changes() ** -******************** -** Zero out all the wt change arrays -**/ -static void zero_changes() -{ -int i,j; - -for (i = 0; i MAXPATS) - numpats = MAXPATS; - -for (patt=0; patt= 0.9) - in_pats[patt][i] = 0.9; - if (in_pats[patt][i] <= 0.1) - in_pats[patt][i] = 0.1; - } - element = 0; - vals_read = fscanf(infile,"%d %d %d %d %d %d %d %d", - &val1, &val2, &val3, &val4, &val5, &val6, &val7, &val8); - - out_pats[patt][element] = (double) val1; element++; - out_pats[patt][element] = (double) val2; element++; - out_pats[patt][element] = (double) val3; element++; - out_pats[patt][element] = (double) val4; element++; - out_pats[patt][element] = (double) val5; element++; - out_pats[patt][element] = (double) val6; element++; - out_pats[patt][element] = (double) val7; element++; - out_pats[patt][element] = (double) val8; element++; -} - -/* printf("\n Closing the input file now. "); */ - -fclose(infile); -return(0); -} - -/********************* -** initialize_net() ** -********************** -** Do all the initialization stuff before beginning -*/ -/* -static int initialize_net() -{ -int err_code; - -randomize_wts(); -zero_changes(); -err_code = read_data_file(); -iteration_count = 1; -return(err_code); -} -*/ - -/********************** -** display_mid_wts() ** -*********************** -** Display the weights on the middle layer neurodes -** NOTE: This routine is not used in the benchmark -** test -- RG -**/ -/* static void display_mid_wts() -{ -int neurode, weight, row, col; - -fprintf(outfile,"\n Weights of Middle Layer neurodes:"); - -for (neurode=0; neurodeadjust==0) -{ - loclustruct->numarrays=0; - for(i=1;i<=MAXLUARRAYS;i++) - { - abase=(fardouble *)AllocateMemory(sizeof(double) * - LUARRAYCOLS*LUARRAYROWS*(i+1),&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - LUFreeMem(a,b,(fardouble *)NULL,(fardouble *)NULL); - ErrorExit(); - } - bbase=(fardouble *)AllocateMemory(sizeof(double) * - LUARRAYROWS*(i+1),&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - LUFreeMem(a,b,abase,(fardouble *)NULL); - ErrorExit(); - } - if(DoLUIteration(a,b,abase,bbase,i)>global_min_ticks) - { loclustruct->numarrays=i; - break; - } - /* - ** Not enough arrays...free them all and try again - */ - FreeMemory((farvoid *)abase,&systemerror); - FreeMemory((farvoid *)bbase,&systemerror); - } - /* - ** Were we able to do it? - */ - if(loclustruct->numarrays==0) - { printf("FPU:LU -- Array limit reached\n"); - LUFreeMem(a,b,abase,bbase); - ErrorExit(); - } -} -else -{ /* - ** Don't need to adjust -- just allocate the proper - ** number of arrays and proceed. - */ - abase=(fardouble *)AllocateMemory(sizeof(double) * - LUARRAYCOLS*LUARRAYROWS*loclustruct->numarrays, - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - LUFreeMem(a,b,(fardouble *)NULL,(fardouble *)NULL); - ErrorExit(); - } - bbase=(fardouble *)AllocateMemory(sizeof(double) * - LUARRAYROWS*loclustruct->numarrays,&systemerror); - if(systemerror) - { - ReportError(errorcontext,systemerror); - LUFreeMem(a,b,abase,(fardouble *)NULL); - ErrorExit(); - } -} -/* -** All's well if we get here. Do the test. -*/ -accumtime=0L; -iterations=(double)0.0; - -do { - accumtime+=DoLUIteration(a,b,abase,bbase, - loclustruct->numarrays); - iterations+=(double)loclustruct->numarrays; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. Be sure to -** show that we don't have to rerun adjustment code. -*/ -loclustruct->iterspersec=iterations / TicksToFracSecs(accumtime); - -if(loclustruct->adjust==0) - loclustruct->adjust=1; - -LUFreeMem(a,b,abase,bbase); -return; -} - -/************** -** LUFreeMem ** -*************** -** Release memory associated with LU benchmark. -*/ -static void LUFreeMem(fardouble *a, fardouble *b, - fardouble *abase,fardouble *bbase) -{ -int systemerror; - -FreeMemory((farvoid *)a,&systemerror); -FreeMemory((farvoid *)b,&systemerror); -FreeMemory((farvoid *)LUtempvv,&systemerror); - -if(abase!=(fardouble *)NULL) FreeMemory((farvoid *)abase,&systemerror); -if(bbase!=(fardouble *)NULL) FreeMemory((farvoid *)bbase,&systemerror); -return; -} - -/****************** -** DoLUIteration ** -******************* -** Perform an iteration of the LU decomposition benchmark. -** An iteration refers to the repeated solution of several -** identical matrices. -*/ -static ulong DoLUIteration(fardouble *a,fardouble *b, - fardouble *abase, fardouble *bbase, - ulong numarrays) -{ -fardouble *locabase; -fardouble *locbbase; -LUdblptr ptra; /* For converting ptr to 2D array */ -ulong elapsed; -ulong j,i; /* Indexes */ - - -/* -** Move the seed arrays (a & b) into the destination -** arrays; -*/ -for(j=0;j big) - big=fabs(a[i][j]); - /* Bail out on singular matrix */ - if(big==(double)0.0) return(0); - LUtempvv[i]=1.0/big; -} - -/* -** Crout's algorithm...loop over columns. -*/ -for(j=0;j=big) - { big=dum; - imax=i; - } - } - if(j!=imax) /* Interchange rows if necessary */ - { for(k=0;k=0;i--) -{ - sum=b[i]; - if(i!=(n-1)) - for(j=(i+1);j 64K chunks of memory. -*/ -/* #define DOS16MEM */ - -/* Define MACMEM to use the Mac's GetPtr call to allocate -** memory (instead of malloc()). -*/ -/* #define MACMEM */ - -/* +++ TIMING +++ */ -/* -** You must define ONLY ONE of the following identifiers to pick -** the timing routine used. -** CLOCKWCPS -** CLOCKWCT -** MACTIMEMGR -** WIN31TIMER -*/ - -/* -** Define CLOCKWCPS if you are using the clock() routine and the -** constant used as the divisor to determine seconds is -** CLOCKS_PER_SEC. This is the default in most cases. -*/ -#define CLOCKWCPS - -/* -** Define CLOCKWCT if you are using the clock() routine and the -** constant used as the divisor to determine seconds is CLK_TCK -*/ -/* #define CLOCKWCT */ - -/* -** Define MACTIMEMGR to use the Mac Time manager routines. -** You'll need to be running at least system 6.0.3 or -** better...extended time manager is recommended (system 7 or -** better). -*/ -/* #define MACTIMEMGR */ - -/* -** Define WIN31TIMER to user the timing routines in TOOLHELP.DLL. -** Gets accuracy down to the millisecond. -*/ -/* #define WIN31TIMER */ - -/* +++ MISCELLANEOUS +++ */ - -/* -** Define DOS16 if you'll be compiling under DOS in 16-bit -** (non DOS-extended) mode. This will enable proper definitions -** for the far*** typedefs -*/ -/* #define DOS16 */ - -/* -** Define MAC if you're compiling on a Macintosh. This -** does a number of things: -** includes unix.h -** Incorporates code to mimic the command line via either -** the console library (Symantec/Think) or the SIOUX -** library (Code Warrior). -*/ -/* #define MAC */ - -/* -** Define LONG64 if your compiler emits 64-bit longs. -** This is typically true of Alpha compilers on Unix -** systems...though, who knows, this may change in the -** future. I MOVED THIS DEFINTION INTO THE FILE pointer.h. DO NOT -** DEFINE IT HERE. IT WILL AUTOMATICALLY BE DEFINED IF NECESSARY. -** Uwe F. Mayer, Dec 15, 1996, Nov 15, 1997 -*/ -/* #define LONG64 */ - -/* -** Define MACCWPROF if you are profiling on the Mac using -** Code Warrior. This enables code that turns off the -** profiler in an evern of an error exit. -*/ -/* #define MACCWPROF */ - -#ifdef MAC -#include -#endif - -/* -** ERROR CODES -*/ -#define ERROR_MEMORY 1 -#define ERROR_MEMARRAY_FULL 2 -#define ERROR_MEMARRAY_NFOUND 3 -#define ERROR_FILECREATE 10 -#define ERROR_FILEREAD 11 -#define ERROR_FILEWRITE 12 -#define ERROR_FILEOPEN 13 -#define ERROR_FILESEEK 14 - -/* -** MINIMUM_TICKS -** -** This sets the default number of minimum ticks. -** It can, of course, be overridden by the input -** command file. -** This ultimately gets loaded into the variable -** global_min_ticks, which specifies the minimum -** number of ticks that must take place between -** a StartStopwatch() and StopStopwatch() call. -** The idea is to reduce error buildup. -*/ -#define MINIMUM_TICKS 1 - -/* -** MINIMUM_SECONDS -** -** Minimum number of seconds to run each test. -*/ -#define MINIMUM_SECONDS 1 - -/* -** MAXPOSLONG -** -** This is the maximum positive long. -*/ -#ifdef LONG64 -#define MAXPOSLONG 0x7FFFFFFFFFFFFFFFL -#else -#define MAXPOSLONG 0x7FFFFFFFL -#endif - -/* -** OTHER DEFINES -*/ -#ifndef MAC -#define TRUE 1 -#define FALSE 0 -#endif - -/* -** Memory array size. Used in SYSSPEC for keeping track -** of re-aligned memory. -*/ -#define MEM_ARRAY_SIZE 20 - -/* -** TYPEDEFS -*/ -#define ulong unsigned long -#define uchar unsigned char -#define uint unsigned int -#define ushort unsigned short -/* -typedef unsigned char uchar; -typedef unsigned int uint; -typedef unsigned short ushort; -typedef unsigned long ulong; -*/ -/* -** The 'farxxx' typedefs were added in deference to DOS, which -** requires far pointers to handle some of the bigger -** memory structures. Other systems will simply -** map 'farxxx' to 'xxx' -*/ -#ifdef DOS16 -typedef void huge farvoid; -typedef double huge fardouble; -typedef long huge farlong; -typedef unsigned long huge farulong; -typedef char huge farchar; -typedef unsigned char huge faruchar; - -#else - -typedef void farvoid; -typedef double fardouble; -typedef long farlong; -typedef unsigned long farulong; -typedef char farchar; -typedef unsigned char faruchar; - -#endif - -/* -** The following typedefs are used when element size -** is critical. You'll have to alter these for -** your specifical platform/compiler. -*/ -typedef unsigned char u8; /* Unsigned 8-bits */ -typedef unsigned short u16; /* Unsigned 16 bits */ -#ifdef LONG64 -typedef unsigned int u32; /* Unsigned 32 bits */ -typedef int int32; /* Signed 32 bit integer */ -#else -typedef unsigned long u32; /* Unsigned 32 bits */ -typedef long int32; /* Signed 32 bit integer */ -#endif - -/***************** -** NUMERIC SORT ** -*****************/ -/* -** DEFINES -*/ - -/* -** The following constant, NUMNUMARRAYS (no, it is not a -** Peter Sellers joke) is the maximum number of arrays -** that can be built by the numeric sorting benchmark -** before it gives up. This maximum is dependent on the -** amount of memory in the system. -*/ -/*#define NUMNUMARRAYS 1000*/ -#define NUMNUMARRAYS 10000 - -/* -** The following constant NUMARRAYSIZE determines the -** default # of elements in each numeric array. Ordinarily -** this is something you shouldn't fool with, though as -** with most of the constants here, it is adjustable. -*/ -#define NUMARRAYSIZE 8111L - - -/* -** TYPEDEFS -*/ -typedef struct { - int adjust; /* Set adjust code */ - ulong request_secs; /* # of seconds requested */ - double sortspersec; /* # of sort iterations per sec */ - ushort numarrays; /* # of arrays */ - ulong arraysize; /* # of elements in array */ -} SortStruct; - -/**************** -** STRING SORT ** -***************** -** Note: The string sort benchmark uses the same structure to -** communicate parameters as does the numeric sort benchmark. -** (i.e., SortStruct...see above. -*/ - -/* -** DEFINES -*/ -/* -** The following constant STRINGARRAYSIZE determines -** the default # of bytes allocated to each string array. -** Though the actual size can be pre-set from the command -** file, this constant should be left unchanged. -*/ -#define STRINGARRAYSIZE 8111L - -/************************ -** BITFIELD OPERATIONS ** -************************* -*/ - -/* -** DEFINES -*/ - -/* -** Following field sets the size of the bitfield array (in longs). -*/ -#ifdef LONG64 -#define BITFARRAYSIZE 16384L -#else -#define BITFARRAYSIZE 32768L -#endif - -/* -** TYPEDEFS -*/ -typedef struct { - int adjust; /* Set adjust code */ - ulong request_secs; /* # of seconds requested */ - double bitopspersec; /* # of bitfield ops per sec */ - ulong bitoparraysize; /* Total # of bitfield ops */ - ulong bitfieldarraysize; /* Bit field array size */ -} BitOpStruct; - -/**************************** -** EMULATED FLOATING POINT ** -****************************/ -/* -** DEFINES -*/ -#define INTERNAL_FPF_PRECISION 4 - -/* -** The following constant is the maximum number of loops -** of the emulated floating point test that the system -** will allow before flagging an error. This is not a -** critical constant, and can be altered if your system is -** a real barn-burner. -*/ -/*#define CPUEMFLOATLOOPMAX 50000L*/ -#define CPUEMFLOATLOOPMAX 500000L - -/* -** Set size of array -*/ -#define EMFARRAYSIZE 3000L - -/* -** TYPEDEFS -*/ -typedef struct { - int adjust; /* Set adjust code */ - ulong request_secs; /* # of seconds requested */ - ulong arraysize; /* Size of array */ - ulong loops; /* Loops per iterations */ - double emflops; /* Results */ -} EmFloatStruct; - -/************************* -** FOURIER COEFFICIENTS ** -*************************/ - -/* -** TYPEDEFS -*/ -typedef struct { - int adjust; /* Set adjust code */ - ulong request_secs; /* # of requested seconds */ - ulong arraysize; /* Size of coeff. arrays */ - double fflops; /* Results */ -} FourierStruct; - -/************************* -** ASSIGNMENT ALGORITHM ** -*************************/ - -/* -** TYPEDEFS -*/ -typedef struct { - int adjust; /* Set adjust code */ - ulong request_secs; /* Requested # of seconds */ - ulong numarrays; /* # of arrays */ - double iterspersec; /* Results */ -} AssignStruct; - -/******************** -** IDEA ENCRYPTION ** -********************/ - -/* -** DEFINES -*/ -/* Following constant defines the max number of loops the -** system will attempt. Keeps things from going off into the -** weeds. */ -/*#define MAXIDEALOOPS 50000L*/ -#define MAXIDEALOOPS 500000L - -/* -** Following constant sets the size of the arrays. -** NOTE: For the IDEA algorithm to work properly, this -** number MUST be some multiple of 8. -*/ -#define IDEAARRAYSIZE 4000L - -/* -** TYPEDEFS -*/ -typedef struct { - int adjust; /* Set adjust code */ - ulong request_secs; /* Requested # of seconds */ - ulong arraysize; /* Size of array */ - ulong loops; /* # of times to convert */ - double iterspersec; /* Results */ -} IDEAStruct; - - -/************************ -** HUFFMAN COMPRESSION ** -************************/ - -/* -** DEFINES -*/ -/* -** MAXHUFFLOOPS -** -** This constant specifies the maximum number of Huffman -** compression loops the system will try for. This keeps -** the test from going off into the weeds. This is not -** a critical constant, and can be increased if your -** system is a real barn-burner. -*/ -/*#define MAXHUFFLOOPS 50000L*/ -#define MAXHUFFLOOPS 500000L - -/* -** Following constant sets the size of the arrays to -** be compressed/uncompressed. -*/ -#define HUFFARRAYSIZE 5000L - -/* -** TYPEDEFS -*/ - -typedef struct { - int adjust; /* Set adjust code */ - ulong request_secs; /* Requested # of seconds */ - ulong arraysize; /* Size of array */ - ulong loops; /* # of times to compress/decompress */ - double iterspersec; /* Results */ -} HuffStruct; - -/******************************** -** BACK PROPAGATION NEURAL NET ** -********************************/ - -/* -** MAXNNETLOOPS -** -** This constant sets the max number of loops through the neural -** net that the system will attempt before giving up. This -** is not a critical constant. You can alter it if your system -** has sufficient horsepower. -*/ -/*#define MAXNNETLOOPS 50000L*/ -#define MAXNNETLOOPS 500000L - -/* -** TYPEDEFS -*/ -typedef struct { - int adjust; /* Set adjust code */ - ulong request_secs; /* Requested # of seconds */ - ulong loops; /* # of times to learn */ - double iterspersec; /* Results */ -} NNetStruct; - -/*********************** -** LU DECOMPOSITION ** -** (Linear Equations) ** -***********************/ - -/* -** MAXLUARRAYS -** -** This sets the upper limit on the number of arrays -** that the benchmark will attempt to build before -** flagging an error. It is not a critical constant, and -** may be increased if your system has the horsepower. -*/ -/*#define MAXLUARRAYS 1000*/ -#define MAXLUARRAYS 10000 - -/* -** TYPEDEFS -*/ -typedef struct { - int adjust; /* Set adjust code */ - ulong request_secs; /* Requested # of seconds */ - ulong numarrays; /* # of arrays */ - double iterspersec; /* Results */ -} LUStruct; - diff --git a/thirdparty/nbench-byte-2.2.3/pointer.c b/thirdparty/nbench-byte-2.2.3/pointer.c deleted file mode 100644 index f4de577e495..00000000000 --- a/thirdparty/nbench-byte-2.2.3/pointer.c +++ /dev/null @@ -1,6 +0,0 @@ -#include -int main(){ - printf("%d",(int)sizeof(long)); - return(0); -} - diff --git a/thirdparty/nbench-byte-2.2.3/sysinfo.c.example b/thirdparty/nbench-byte-2.2.3/sysinfo.c.example deleted file mode 100644 index db650f03028..00000000000 --- a/thirdparty/nbench-byte-2.2.3/sysinfo.c.example +++ /dev/null @@ -1,10 +0,0 @@ -sprintf(buffer,"**System used for compilation:\n"); -output_string(buffer); -sprintf(buffer,"**Linux mimi 2.0.31 #5 Thu Oct 23 10:02:08 CDT 1997 i486\n"); -output_string(buffer); -sprintf(buffer,"**C compiler: gcc version 2.7.2.3\n"); -output_string(buffer); -sprintf(buffer,"**libc: libc.so.5.4.38\n"); -output_string(buffer); -sprintf(buffer,"**Date of compilation: Thu Nov 20 10:04:43 CST 1997\n"); -output_string(buffer); diff --git a/thirdparty/nbench-byte-2.2.3/sysinfo.c.template b/thirdparty/nbench-byte-2.2.3/sysinfo.c.template deleted file mode 100644 index c1a986cb900..00000000000 --- a/thirdparty/nbench-byte-2.2.3/sysinfo.c.template +++ /dev/null @@ -1,10 +0,0 @@ -sprintf(buffer,"**System used for compilation:\n"); -output_string(buffer); -sprintf(buffer,"**%SYSTEM%\n"); -output_string(buffer); -sprintf(buffer,"**C compiler: %CCVERSION%\n"); -output_string(buffer); -sprintf(buffer,"**libc: %LIBCVERSION%\n"); -output_string(buffer); -sprintf(buffer,"**Date of compilation: %DATE%\n"); -output_string(buffer); diff --git a/thirdparty/nbench-byte-2.2.3/sysinfo.sh b/thirdparty/nbench-byte-2.2.3/sysinfo.sh deleted file mode 100644 index 57754fe3708..00000000000 --- a/thirdparty/nbench-byte-2.2.3/sysinfo.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/sh - -# the arguments of this script are the compiler name and flags - -# try to solve a chicken-and-egg problem on SunOS -# ucb's test program does not handle -L like the other test programs -# let's try to find another implementation -if test -x /bin/test; then - TEST=/bin/test; -else - if test -x /usr/bin/test; then - TEST=/usr/bin/test; - else - # cross your fingers that it's not like ucb test - TEST=test; - fi -fi - -compiler=`echo $* | sed -e 's/-static//g' -e 's/-Bstatic//g'` -if $TEST `basename $1` = "gcc" && ($compiler -v) >/dev/null 2>&1 ; then -# Cygwin writes more than one line with "version" in it - gccversion=`$compiler -v 2>&1 | sed -e "/version/!d" | tail -n 1` -else - gccversion="$1" -fi - -libcversion="" -if ($* hello.c -o hello) >/dev/null 2>&1; then - ldd_output=`(ldd hello) 2>&1` - libcversion=`echo $ldd_output | sed -e 's/.*static.*/static/' \ - -e 's/.*not a dynamic.*/static/'` - if $TEST "$libcversion" = "static" ; then - if ($compiler hello.c -o hello) >/dev/null 2>&1; then - if (ldd hello) >/dev/null 2>/dev/null; then - libcversion=`(ldd hello) 2>&1` - libcversion=`echo $libcversion | sed -e '/libc/!d'\ - -e 's/^[ ]*//' \ - -e 's/.*=>[ ][ ]*\([^ ]*\).*/\1/'` - # remember the current directory - current=`pwd` - while $TEST -L "$libcversion" && ! $TEST "$libcversion" = "" ; do - libcitself=`basename $libcversion` - libpath=`echo $libcversion | sed -e "s/$libcitself$//"` - if $TEST -d "$libpath" ; then - cd $libpath - fi - if ls $libcitself >/dev/null 2>/dev/null ; then - libcversion=`ls -l $libcitself | \ - sed -e 's/.*->[ ][ ]*\(.*\)$/\1/'` - else - # something must have gone wrong, let's bail out - libcversion="" - fi - done - # return to the current directory - cd $current - fi - fi - else - libcversion="" - fi -fi - -rm -f sysinfo.crm sysinfoc.c hello - -# this bombs out on Ultrix which expect "cut -d" - -compsystem=`uname -a | cut -b 1-78` -compdate=`date|cut -b1-55` - -# let's hope that ctrl-c is not part of any string here -# this also will barf later if " is in any of the strings - -for i in sysinfo.c sysinfoc.c ; do - sed -e "s%CCVERSION%$gccversion" -e "s%LIBCVERSION%$libcversion"\ - -e "s%SYSTEM%$compsystem" -e "s%DATE%$compdate"\ - ${i}.template > $i -done diff --git a/thirdparty/nbench-byte-2.2.3/sysinfoc.c.example b/thirdparty/nbench-byte-2.2.3/sysinfoc.c.example deleted file mode 100644 index 7da71ace49d..00000000000 --- a/thirdparty/nbench-byte-2.2.3/sysinfoc.c.example +++ /dev/null @@ -1,4 +0,0 @@ -sprintf(buffer,"C compiler : gcc version 2.7.2.3\n"); -output_string(buffer); -sprintf(buffer,"libc : libc.so.5.4.38\n"); -output_string(buffer); diff --git a/thirdparty/nbench-byte-2.2.3/sysinfoc.c.template b/thirdparty/nbench-byte-2.2.3/sysinfoc.c.template deleted file mode 100644 index 922a5de91bb..00000000000 --- a/thirdparty/nbench-byte-2.2.3/sysinfoc.c.template +++ /dev/null @@ -1,4 +0,0 @@ -sprintf(buffer,"C compiler : %CCVERSION%\n"); -output_string(buffer); -sprintf(buffer,"libc : %LIBCVERSION%\n"); -output_string(buffer); diff --git a/thirdparty/nbench-byte-2.2.3/sysspec.c b/thirdparty/nbench-byte-2.2.3/sysspec.c deleted file mode 100644 index a97010dd1f8..00000000000 --- a/thirdparty/nbench-byte-2.2.3/sysspec.c +++ /dev/null @@ -1,884 +0,0 @@ - -/* -** sysspec.c -** System-specific routines. -** -** BYTEmark (tm) -** BYTE's Native Mode Benchmarks -** Rick Grehan, BYTE Magazine -** -** Creation: -** Revision: 3/95;10/95 -** -** DISCLAIMER -** The source, executable, and documentation files that comprise -** the BYTEmark benchmarks are made available on an "as is" basis. -** This means that we at BYTE Magazine have made every reasonable -** effort to verify that the there are no errors in the source and -** executable code. We cannot, however, guarantee that the programs -** are error-free. Consequently, McGraw-HIll and BYTE Magazine make -** no claims in regard to the fitness of the source code, executable -** code, and documentation of the BYTEmark. -** Furthermore, BYTE Magazine, McGraw-Hill, and all employees -** of McGraw-Hill cannot be held responsible for any damages resulting -** from the use of this code or the results obtained from using -** this code. -*/ - -/*********************************** -** SYSTEM-SPECIFIC ROUTINES ** -************************************ -** -** These are the routines that provide functions that are -** system-specific. If the benchmarks are to be ported -** to new hardware/new O.S., this is the first place to -** start. -*/ -#include "sysspec.h" - -#ifdef DOS16 -#include -#include -#include -#endif -/********************************* -** MEMORY MANAGEMENT ROUTINES ** -*********************************/ - - -/**************************** -** AllocateMemory -** This routine returns a void pointer to a memory -** block. The size of the memory block is given in bytes -** as the first argument. This routine also returns an -** error code in the second argument. -** 10/95 Update: -** Added an associative array for memory alignment reasons. -** mem_array[2][MEM_ARRAY_SIZE] -** mem_array[0][n] = Actual address (from malloc) -** mem_array[1][n] = Aligned address -** Currently, mem_array[][] is only used if you use malloc; -** it is not used for the 16-bit DOS and MAC versions. -*/ -farvoid *AllocateMemory(unsigned long nbytes, /* # of bytes to alloc */ - int *errorcode) /* Returned error code */ -{ -#ifdef DOS16MEM -union REGS registers; -unsigned short nparas; /* # of paragraphs */ - -/* -** Set # of paragraphs to nbytes/16 +1. The +1 is a -** slop factor. -*/ -nparas=(unsigned short)(nbytes/16L) + 1; - -/* -** Set incoming registers. -*/ -registers.h.ah=0x48; /* Allocate memory */ -registers.x.bx=nparas; /* # of paragraphs */ - - -intdos(®isters,®isters); /* Call DOS */ - -/* -** See if things succeeded. -*/ -if(registers.x.cflag) -{ printf("error: %d Lgst: %d\n",registers.x.ax,registers.x.bx); - *errorcode=ERROR_MEMORY; - return((farvoid *)NULL); -} - -/* -** Create a farvoid pointer to return. -*/ -*errorcode=0; -return((farvoid *)MK_FP(registers.x.ax,0)); - -#endif - -#ifdef MACMEM -/* -** For MAC CodeWarrior, we'll use the MacOS NewPtr call -*/ -farvoid *returnval; -returnval=(farvoid *)NewPtr((Size)nbytes); -if(returnval==(farvoid *)NULL) - *errorcode=ERROR_MEMORY; -else - *errorcode=0; -return(returnval); -#endif - -#ifdef MALLOCMEM -/* -** Everyone else, its pretty straightforward, given -** that you use a 32-bit compiler which treats size_t as -** a 4-byte entity. -*/ -farvoid *returnval; /* Return value */ -ulong true_addr; /* True address */ -ulong adj_addr; /* Adjusted address */ - -returnval=(farvoid *)malloc((size_t)(nbytes+2L*(long)global_align)); -if(returnval==(farvoid *)NULL) - *errorcode=ERROR_MEMORY; -else - *errorcode=0; - -/* -** Check for alignment -*/ -adj_addr=true_addr=(ulong)returnval; -if(global_align==0) -{ - if(AddMemArray(true_addr, adj_addr)) - *errorcode=ERROR_MEMARRAY_FULL; - return(returnval); -} - -if(global_align==1) -{ - if(true_addr%2==0) adj_addr++; -} -else -{ - while(adj_addr%global_align!=0) ++adj_addr; - if(adj_addr%(global_align*2)==0) adj_addr+=global_align; -} -returnval=(void *)adj_addr; -if(AddMemArray(true_addr,adj_addr)) - *errorcode=ERROR_MEMARRAY_FULL; -return(returnval); -#endif - -} - - -/**************************** -** FreeMemory -** This is the reverse of AllocateMemory. The memory -** block passed in is freed. Should an error occur, -** that error is returned in errorcode. -*/ -void FreeMemory(farvoid *mempointer, /* Pointer to memory block */ - int *errorcode) -{ -#ifdef DOS16MEM -/* -** 16-bit DOS VERSION!! -*/ -unsigned int segment; -unsigned int offset; -union REGS registers; -struct SREGS sregisters; - -/* -** First get the segment/offset of the farvoid pointer. -*/ -segment=FP_SEG(mempointer); -offset=FP_OFF(mempointer); - -/* -** Align the segment properly. For as long as offset > 16, -** subtract 16 from offset and add 1 to segment. -*/ -while(offset>=16) -{ offset-=16; - segment++; -} - -/* -** Build the call to DOS -*/ -registers.h.ah=0x49; /* Free memory */ -sregisters.es=segment; - -intdosx(®isters,®isters,&sregisters); - -/* -** Check for error -*/ -if(registers.x.cflag) -{ *errorcode=ERROR_MEMORY; - return; -} - -*errorcode=0; -return; -#endif - -#ifdef MACMEM -DisposPtr((Ptr)mempointer); -*errorcode=0; -return; -#endif - -#ifdef MALLOCMEM -ulong adj_addr, true_addr; - -/* Locate item in memory array */ -adj_addr=(ulong)mempointer; -if(RemoveMemArray(adj_addr, &true_addr)) -{ *errorcode=ERROR_MEMARRAY_NFOUND; - return; -} -mempointer=(void *)true_addr; -free(mempointer); -*errorcode=0; -return; -#endif -} - -/**************************** -** MoveMemory -** Moves n bytes from a to b. Handles overlap. -** In most cases, this is just a memmove operation. -** But, not in DOS....noooo.... -*/ -void MoveMemory( farvoid *destination, /* Destination address */ - farvoid *source, /* Source address */ - unsigned long nbytes) -{ - -/* +++16-bit DOS VERSION+++ */ -#ifdef DOS16MEM - - FarDOSmemmove( destination, source, nbytes); - -#else - -memmove(destination, source, nbytes); - -#endif -} - -#ifdef DOS16MEM - -/**************************** -** FarDOSmemmove -** Performs the same function as memmove for DOS when -** the arrays are defined with far pointers. -*/ -void FarDOSmemmove(farvoid *destination, /* Destination pointer */ - farvoid *source, /* Source pointer */ - unsigned long nbytes) /* # of bytes to move */ -{ -unsigned char huge *uchsource; /* Temp source */ -unsigned char huge *uchdest; /* Temp destination */ -unsigned long saddr; /* Source "true" address */ -unsigned long daddr; /* Destination "true" address */ - - -/* -** Get unsigned char pointer equivalents -*/ -uchsource=(unsigned char huge *)source; -uchdest=(unsigned char huge *)destination; - -/* -** Calculate true address of source and destination and -** compare. -*/ -saddr=(unsigned long)(FP_SEG(source)*16 + FP_OFF(source)); -daddr=(unsigned long)(FP_SEG(destination)*16 + FP_OFF(destination)); - -if(saddr > daddr) -{ - /* - ** Source is greater than destination. - ** Use a series of standard move operations. - ** We'll move 65535 bytes at a time. - */ - while(nbytes>=65535L) - { _fmemmove((farvoid *)uchdest, - (farvoid *)uchsource, - (size_t) 65535); - uchsource+=65535; /* Advance pointers */ - uchdest+=65535; - nbytes-=65535; - } - - /* - ** Move remaining bytes - */ - if(nbytes!=0L) - _fmemmove((farvoid *)uchdest, - (farvoid *)uchsource, - (size_t)(nbytes & 0xFFFF)); - -} -else -{ - /* - ** Destination is greater than source. - ** Advance pointers to the end of their - ** respective blocks. - */ - uchsource+=nbytes; - uchdest+=nbytes; - - /* - ** Again, move 65535 bytes at a time. However, - ** "back" the pointers up before doing the - ** move. - */ - while(nbytes>=65535L) - { - uchsource-=65535; - uchdest-=65535; - _fmemmove((farvoid *)uchdest, - (farvoid *)uchsource, - (size_t) 65535); - nbytes-=65535; - } - - /* - ** Move remaining bytes. - */ - if(nbytes!=0L) - { uchsource-=nbytes; - uchdest-=nbytes; - _fmemmove((farvoid *)uchdest, - (farvoid *)uchsource, - (size_t)(nbytes & 0xFFFF)); - } -} -return; -} -#endif - -/*********************************** -** MEMORY ARRAY HANDLING ROUTINES ** -***********************************/ -/**************************** -** InitMemArray -** Initialize the memory array. This simply amounts to -** setting mem_array_ents to zero, indicating that there -** isn't anything in the memory array. -*/ -void InitMemArray(void) -{ -mem_array_ents=0; -return; -} - -/*************************** -** AddMemArray -** Add a pair of items to the memory array. -** true_addr is the true address (mem_array[0][n]) -** adj_addr is the adjusted address (mem_array[0][n]) -** Returns 0 if ok -** -1 if not enough room -*/ -int AddMemArray(ulong true_addr, - ulong adj_addr) -{ -if(mem_array_ents>=MEM_ARRAY_SIZE) - return(-1); - -mem_array[0][mem_array_ents]=true_addr; -mem_array[1][mem_array_ents]=adj_addr; -mem_array_ents++; -return(0); -} - -/************************* -** RemoveMemArray -** Given an adjusted address value (mem_array[1][n]), locate -** the entry and remove it from the mem_array. -** Also returns the associated true address. -** Returns 0 if ok -** -1 if not found. -*/ -int RemoveMemArray(ulong adj_addr,ulong *true_addr) -{ -int i,j; - -/* Locate the item in the array. */ -for(i=0;i -#include -#include -#include - -#include "nmglobal.h" - -#if !defined(MAC) && !defined(OSX) -#include -#endif - - -/* -** System-specific includes -*/ - -#ifdef DOS16MEM -#include "dos.h" -#endif - -/* #include "time.h" -#include "io.h" -#include "fcntl.h" -#include "sys\stat.h" */ -/* Removed for MSVC++ -#include "alloc.h" -*/ - -/* -** MAC Time Manager routines (from Code Warrior) -*/ -#ifdef MACTIMEMGR -#include -#include -#include -#include -extern struct TMTask myTMTask; -extern long MacHSTdelay,MacHSTohead; -#endif - -/* -** Windows 3.1 timer defines -*/ -#ifdef WIN31TIMER -#include -#include -TIMERINFO win31tinfo; -HANDLE hThlp; -FARPROC lpfn; -#endif - -/************** -** EXTERNALS ** -**************/ -extern ulong mem_array[2][MEM_ARRAY_SIZE]; -extern int mem_array_ents; -extern int global_align; - -/**************************** -** FUNCTION PROTOTYPES ** -****************************/ - -farvoid *AllocateMemory(unsigned long nbytes, - int *errorcode); - -void FreeMemory(farvoid *mempointer, - int *errorcode); - -void MoveMemory( farvoid *destination, - farvoid *source, - unsigned long nbytes); - -#ifdef DOS16MEM -void FarDOSmemmove(farvoid *destination, - farvoid *source, - unsigned long nbytes); -#endif - -void InitMemArray(void); - -int AddMemArray(ulong true_addr, ulong adj_addr); - -int RemoveMemArray(ulong adj_addr,ulong *true_addr); - -void ReportError(char *context, int errorcode); - -void ErrorExit(); - -void CreateFile(char *filename, - int *errorcode); - -#ifdef DOS16 -int bmOpenFile(char *fname, - int *errorcode); - -void CloseFile(int fhandle, - int *errorcode); - -void readfile(int fhandle, - unsigned long offset, - unsigned long nbytes, - void *buffer, - int *errorcode); - -void writefile(int fhandle, - unsigned long offset, - unsigned long nbytes, - void *buffer, - int *errorcode); -#endif - -#ifdef LINUX -FILE *bmOpenFile(char *fname, - int *errorcode); - -void CloseFile(FILE *fhandle, - int *errorcode); - -void readfile(FILE *fhandle, - unsigned long offset, - unsigned long nbytes, - void *buffer, - int *errorcode); - -void writefile(FILE *fhandle, - unsigned long offset, - unsigned long nbytes, - void *buffer, - int *errorcode); - -#endif - -unsigned long StartStopwatch(); - -unsigned long StopStopwatch(unsigned long startticks); - -unsigned long TicksToSecs(unsigned long tickamount); - -double TicksToFracSecs(unsigned long tickamount); - diff --git a/thirdparty/nbench-byte-2.2.3/wordcat.h b/thirdparty/nbench-byte-2.2.3/wordcat.h deleted file mode 100644 index 9f18b4265f7..00000000000 --- a/thirdparty/nbench-byte-2.2.3/wordcat.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -** wordcat.h -** Word catalog -** BYTEmark (tm) -** BYTE's Native Mode Benchmarks -** Rick Grehan, BYTE Magazine -** -** Creation: -** Revision: 3/95 -** -** DISCLAIMER -** The source, executable, and documentation files that comprise -** the BYTEmark benchmarks are made available on an "as is" basis. -** This means that we at BYTE Magazine have made every reasonable -** effort to verify that the there are no errors in the source and -** executable code. We cannot, however, guarantee that the programs -** are error-free. Consequently, McGraw-HIll and BYTE Magazine make -** no claims in regard to the fitness of the source code, executable -** code, and documentation of the BYTEmark. -** Furthermore, BYTE Magazine, McGraw-Hill, and all employees -** of McGraw-Hill cannot be held responsible for any damages resulting -** from the use of this code or the results obtained from using -** this code. -*/ - -/* -** Word catalog -*/ -#define WORDCATSIZE 50 - -char *wordcatarray[WORDCATSIZE] = -{ "Hello", - "He", - "Him", - "the", - "this", - "that", - "though", - "rough", - "cough", - "obviously", - "But", - "but", - "bye", - "begin", - "beginning", - "beginnings", - "of", - "our", - "ourselves", - "yourselves", - "to", - "together", - "togetherness", - "from", - "either", - "I", - "A", - "return", - "However", - "that", - "example", - "yet", - "quickly", - "all", - "if", - "were", - "includes", - "always", - "never", - "not", - "small", - "returns", - "set", - "basic", - "Entered", - "with", - "used", - "shown", - "you", - "know" }; diff --git a/thirdparty/snark/AUTHORS b/thirdparty/snark/AUTHORS deleted file mode 100644 index 9d2f9024ec1..00000000000 --- a/thirdparty/snark/AUTHORS +++ /dev/null @@ -1,2 +0,0 @@ -Mark Wielaard -Elizabeth Fong diff --git a/thirdparty/snark/COPYING b/thirdparty/snark/COPYING deleted file mode 100644 index d60c31a97a5..00000000000 --- a/thirdparty/snark/COPYING +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/thirdparty/snark/ChangeLog b/thirdparty/snark/ChangeLog deleted file mode 100644 index 75304f17c59..00000000000 --- a/thirdparty/snark/ChangeLog +++ /dev/null @@ -1,487 +0,0 @@ -2003-06-27 14:24 Mark Wielaard - - * README: Update version number and explain new features. - -2003-06-27 13:51 Mark Wielaard - - * Makefile, org/klomp/snark/GnomeInfoWindow.java, - org/klomp/snark/GnomePeerList.java, - org/klomp/snark/PeerCoordinator.java, - org/klomp/snark/SnarkGnome.java: Add GnomeInfoWindow. - -2003-06-27 00:37 Mark Wielaard - - * org/klomp/snark/Snark.java: Implement 'info' and 'list' commands. - -2003-06-27 00:05 Mark Wielaard - - * Makefile, org/klomp/snark/GnomePeerList.java, - org/klomp/snark/SnarkGnome.java: Add GnomePeerList to show state of - connected peers. - -2003-06-27 00:04 Mark Wielaard - - * org/klomp/snark/: Peer.java, PeerID.java: Make Comparable. - -2003-06-23 23:32 Mark Wielaard - - * org/klomp/snark/PeerMonitorTask.java: Correctly update - lastDownloaded and lastUploaded. - -2003-06-23 23:20 Mark Wielaard - - * org/klomp/snark/Snark.java: When checking storage use the - MetaInfo from the storage. - -2003-06-23 21:47 Mark Wielaard - - * org/klomp/snark/Storage.java: Fill piece hashes, not info hashes. - -2003-06-23 21:42 Mark Wielaard - - * org/klomp/snark/MetaInfo.java: New package private - getPieceHashes() method. - -2003-06-22 19:49 Mark Wielaard - - * README, TODO, org/klomp/snark/Snark.java: Add new command line - switch --no-commands. Don't read interactive commands or show - usage info. - -2003-06-22 19:26 Mark Wielaard - - * Makefile, org/klomp/snark/PeerCheckerTask.java, - org/klomp/snark/PeerMonitorTask.java, org/klomp/snark/Snark.java: - Split peer statistic reporting from PeerCheckerTask into - PeerMonitorTask. Use new task in Snark text ui. - -2003-06-22 18:32 Mark Wielaard - - * org/klomp/snark/Snark.java: Only print peer id when debug level - is INFO or higher. - -2003-06-22 18:00 Mark Wielaard - - * org/klomp/snark/ShutdownListener.java: Add new ShutdownListener - interface. - -2003-06-22 17:18 Mark Wielaard - - * TODO: Text UI item to not read from stdin. - -2003-06-22 17:18 Mark Wielaard - - * snark-gnome.sh: kaffe java-gnome support (but crashes hard at the - moment). - -2003-06-22 14:04 Mark Wielaard - - * Makefile, org/klomp/snark/CoordinatorListener.java, - org/klomp/snark/PeerCoordinator.java, - org/klomp/snark/ProgressListener.java, org/klomp/snark/Snark.java, - org/klomp/snark/SnarkGnome.java, - org/klomp/snark/SnarkShutdown.java, org/klomp/snark/Storage.java, - org/klomp/snark/StorageListener.java: Split ProgressListener into - Storage, Coordinator and Shutdown listener. - -2003-06-20 19:06 Mark Wielaard - - * org/klomp/snark/: PeerCoordinator.java, Snark.java, - SnarkGnome.java, Storage.java: Progress listeners for both Storage - and PeerCoordinator. - -2003-06-20 14:50 Mark Wielaard - - * Makefile, org/klomp/snark/PeerCoordinator.java, - org/klomp/snark/ProgressListener.java, - org/klomp/snark/SnarkGnome.java: Add ProgressListener. - -2003-06-20 13:22 Mark Wielaard - - * org/klomp/snark/SnarkGnome.java: Add Pieces collected field. - -2003-06-20 12:26 Mark Wielaard - - * org/klomp/snark/: PeerCoordinator.java, PeerListener.java, - PeerState.java: Add PeerListener.downloaded() which gets called on - chunk updates. Keep PeerCoordinator.downloaded up to date using - this remove adjusting in gotPiece() except when we receive a bad - piece. - -2003-06-16 00:27 Mark Wielaard - - * Makefile, snark-gnome.sh, org/klomp/snark/Snark.java, - org/klomp/snark/SnarkGnome.java: Start of a Gnome GUI. - -2003-06-05 13:19 Mark Wielaard - - * org/klomp/snark/PeerCoordinator.java: Don't remove a BAD piece - from the wantedPieces list. Revert to synchronizing on - wantedPieces for all relevant sections. - -2003-06-03 21:09 Mark Wielaard - - * org/klomp/snark/Snark.java: Only call readLine() when !quit. - Always print exception when fatal() is called. - -2003-06-01 23:12 Mark Wielaard - - * README: Set release version to 0.4. - -2003-06-01 22:59 Mark Wielaard - - * org/klomp/snark/PeerConnectionIn.java: Handle negative length - prefixes (terminates connection). - -2003-06-01 21:34 Mark Wielaard - - * org/klomp/snark/: Snark.java, SnarkShutdown.java: Implement - correct shutdown and read commands from stdin. - -2003-06-01 21:34 Mark Wielaard - - * org/klomp/snark/TrackerInfo.java: Check that interval and peers - list actually exist. - -2003-06-01 21:33 Mark Wielaard - - * org/klomp/snark/Storage.java: Implement close(). - -2003-06-01 21:05 Mark Wielaard - - * org/klomp/snark/PeerState.java: Fix debug logging. - -2003-06-01 20:55 Mark Wielaard - - * org/klomp/snark/PeerCoordinator.java: Implement halt(). - -2003-06-01 20:55 Mark Wielaard - - * org/klomp/snark/ConnectionAcceptor.java: Rename stop() to halt(). - -2003-06-01 17:35 Mark Wielaard - - * org/klomp/snark/PeerState.java: Drop lock on this when calling - addRequest() from havePiece(). - -2003-06-01 14:46 Mark Wielaard - - * README, org/klomp/snark/ConnectionAcceptor.java, - org/klomp/snark/HttpAcceptor.java, org/klomp/snark/Peer.java, - org/klomp/snark/PeerCheckerTask.java, - org/klomp/snark/PeerConnectionIn.java, - org/klomp/snark/PeerConnectionOut.java, - org/klomp/snark/PeerCoordinator.java, - org/klomp/snark/PeerState.java, org/klomp/snark/Snark.java, - org/klomp/snark/SnarkShutdown.java, org/klomp/snark/Storage.java, - org/klomp/snark/Tracker.java, org/klomp/snark/TrackerClient.java: - Add debug/log level. - -2003-05-31 23:04 Mark Wielaard - - * org/klomp/snark/: PeerCheckerTask.java, PeerCoordinator.java: Use - just one lock (peers) for all synchronization (even for - wantedPieces). Let PeerChecker handle real disconnect and keep - count of uploaders. - -2003-05-31 22:29 Mark Wielaard - - * org/klomp/snark/: Peer.java, PeerConnectionIn.java: Set state to - null on first disconnect() call. So always check whether it might - already be null. Helps disconnect check. - -2003-05-31 22:27 Mark Wielaard - - * org/klomp/snark/PeerConnectionOut.java: Don't explicitly close - the DataOutputStream (if another thread is using it libgcj seems to - not like it very much). - -2003-05-30 21:33 Mark Wielaard - - * org/klomp/snark/PeerConnectionOut.java: Cancel - (un)interested/(un)choke when (inverse) is still in send queue. - Remove pieces from send queue when choke message is actaully send. - -2003-05-30 19:32 Mark Wielaard - - * org/klomp/snark/PeerState.java: Make sure listener.wantPiece(int) - is never called while lock on this is held. - -2003-05-30 19:00 Mark Wielaard - - * org/klomp/snark/PeerConnectionOut.java: Indentation cleanup. - -2003-05-30 17:50 Mark Wielaard - - * org/klomp/snark/Storage.java: Only synchronize on bitfield as - long as necessary. - -2003-05-30 17:43 Mark Wielaard - - * org/klomp/snark/Tracker.java: Identing cleanup. - -2003-05-30 16:32 Mark Wielaard - - * org/klomp/snark/PeerState.java: Better error message. - -2003-05-30 15:11 Mark Wielaard - - * org/klomp/snark/PeerState.java: Make sure not to hold the lock on - this when calling the listener to prevent deadlocks. Implement - handling and sending of cancel messages. - -2003-05-30 14:50 Mark Wielaard - - * org/klomp/snark/PeerCoordinator.java: First check if we still - want a piece before trying to add it to the Storage. - -2003-05-30 14:49 Mark Wielaard - - * org/klomp/snark/PeerConnectionOut.java: Implement - sendCancel(Request). Add cancelRequest(int, int, int). - -2003-05-30 14:46 Mark Wielaard - - * org/klomp/snark/Request.java: Add hashCode() and equals(Object) - methods. - -2003-05-30 14:45 Mark Wielaard - - * org/klomp/snark/Peer.java: Fix wheter -> whether javadoc - comments. Mark state null immediatly after calling - listener.disconnected(). Call PeerState.havePiece() not - PeerConnectionOut.sendHave() directly. - -2003-05-25 19:23 Mark Wielaard - - * TODO: Add PeerCoordinator TODO for connecting to seeds. - -2003-05-23 12:12 Mark Wielaard - - * Makefile: Create class files with jikes again. - -2003-05-18 22:01 Mark Wielaard - - * org/klomp/snark/: PeerCheckerTask.java, PeerCoordinator.java: - Prefer to (optimistically) unchoke first those peers that unchoked - us. And make sure to not unchoke a peer that we just choked. - -2003-05-18 21:48 Mark Wielaard - - * org/klomp/snark/Peer.java: Fix isChoked() to not always return - true. - -2003-05-18 14:46 Mark Wielaard - - * org/klomp/snark/: Peer.java, PeerCheckerTask.java, - PeerCoordinator.java, PeerState.java: Remove separate Peer - downloading/uploading states. Keep choke and interest always up to - date. Uploading is now just when we are not choking the peer. - Downloading is now defined as being unchoked and interesting. - CHECK_PERIOD is now 20 seconds. MAX_CONNECTIONS is now 24. - MAX_DOWNLOADERS doesn't exists anymore. We download whenever we can - from peers. - -2003-05-18 13:57 Mark Wielaard - - * org/klomp/snark/PeerConnectionOut.java: Remove piece messages - from queue when we are choking. (They will have to be rerequested - when we unchoke the peer again.) - -2003-05-15 00:08 Mark Wielaard - - * org/klomp/snark/PeerState.java: Ignore missed chunk requests, - don't requeue them. - -2003-05-15 00:06 Mark Wielaard - - * org/klomp/snark/Request.java: Add sanity check - -2003-05-10 15:47 Mark Wielaard - - * org/klomp/snark/Snark.java: Add extra '(' to usage message. - -2003-05-10 15:22 Mark Wielaard - - * README: Set version to 0.3 (The Bakers Tale). - -2003-05-10 15:17 Mark Wielaard - - * org/klomp/snark/PeerState.java: Mention received piece in warning - message. - -2003-05-10 03:20 Mark Wielaard - - * org/klomp/snark/: PeerConnectionIn.java, PeerState.java, - Request.java: Remove currentRequest and handle all piece messages - from the lastRequested list. - -2003-05-09 20:02 Mark Wielaard - - * org/klomp/snark/PeerState.java: Fix nothing requested warning - message. - -2003-05-09 19:59 Mark Wielaard - - * org/klomp/snark/PeerConnectionOut.java: Piece messages are big. - So if there are other (control) messages make sure they are send - first. Also remove request messages from the queue if we are - currently being choked to prevent them from being send even if we - get unchoked a little later. (Since we will resent them anyway in - that case.) - -2003-05-09 18:33 Mark Wielaard - - * org/klomp/snark/: Peer.java, PeerCheckerTask.java, - PeerCoordinator.java, PeerID.java: New definition of PeerID.equals - (port + address + id) and new method PeerID.sameID (only id). These - are used to really see if we already have a connection to a certain - peer (active setup vs passive setup). - -2003-05-08 03:05 Mark Wielaard - - * org/klomp/snark/PeerState.java: Use Snark.debug() not - System.out.println(). - -2003-05-06 20:29 Mark Wielaard - - * org/klomp/snark/PeerState.java: s/noting/nothing/ - -2003-05-06 20:28 Mark Wielaard - - * Makefile: s/lagacy/legacy/ - -2003-05-05 23:17 Mark Wielaard - - * README: Set version to 0.2, explain new functionality and add - examples. - -2003-05-05 22:42 Mark Wielaard - - * .cvsignore, Makefile, org/klomp/snark/StaticSnark.java: Enable - -static binary creation. - -2003-05-05 22:42 Mark Wielaard - - * org/klomp/snark/Tracker.java: Disable --ip support. - -2003-05-05 21:02 Mark Wielaard - - * org/klomp/snark/: HttpAcceptor.java, PeerCheckerTask.java, - PeerCoordinator.java, TrackerClient.java: Use Snark.debug() not - System.out.println(). - -2003-05-05 21:01 Mark Wielaard - - * org/klomp/snark/PeerConnectionIn.java: Be prepared to handle the - case where currentRequest is null. - -2003-05-05 21:00 Mark Wielaard - - * org/klomp/snark/Snark.java: Improve argument parsing errors. - -2003-05-05 21:00 Mark Wielaard - - * Makefile: Use gcj -C again for creating the class files. - -2003-05-05 09:24 Mark Wielaard - - * org/klomp/snark/PeerState.java: Just clear outstandingRequests, - never make it null. - -2003-05-05 02:55 Mark Wielaard - - * org/klomp/snark/TrackerClient.java: Always retry both first - started event and every other event as long the TrackerClient is - not stopped. - -2003-05-05 02:54 Mark Wielaard - - * org/klomp/snark/Snark.java: Remove double assignment port. - -2003-05-05 02:54 Mark Wielaard - - * TODO: Add Tracker TODO item. - -2003-05-04 23:38 Mark Wielaard - - * org/klomp/snark/: ConnectionAcceptor.java, MetaInfo.java, - Snark.java, Storage.java, Tracker.java: Add info hash calcultation - to MetaInfo. Add torrent creation to Storage. Add ip parameter - handling to Tracker. Make ConnectionAcceptor handle - null/non-existing HttpAcceptors. Add debug output, --ip handling - and all the above to Snark. - -2003-05-04 23:36 Mark Wielaard - - * org/klomp/snark/TrackerClient.java: Handle all failing requests - the same (print a warning). - -2003-05-03 15:46 Mark Wielaard - - * org/klomp/snark/: Peer.java, PeerID.java, TrackerInfo.java: Split - Peer and PeerID a little more. - -2003-05-03 15:44 Mark Wielaard - - * org/klomp/snark/MetaInfo.java: Add reannounce() and - getTorrentData(). - -2003-05-03 15:38 Mark Wielaard - - * org/klomp/snark/: PeerCheckerTask.java, PeerCoordinator.java: - More concise verbose/debug output. Always use addUpDownloader() to - set peers upload or download state to true. - -2003-05-03 13:38 Mark Wielaard - - * org/klomp/snark/TrackerClient.java: Compile fixes. - -2003-05-03 13:32 Mark Wielaard - - * org/klomp/snark/TrackerClient.java: Only generate fatal() call on - first Tracker access. Otherwise just print a warning error message. - -2003-05-03 03:10 Mark Wielaard - - * org/klomp/snark/PeerState.java: Better handle resending - outstanding pieces and try to recover better from unrequested - pieces. - -2003-05-02 21:33 Mark Wielaard - - * Makefile, org/klomp/snark/HttpAcceptor.java, - org/klomp/snark/MetaInfo.java, org/klomp/snark/PeerID.java, - org/klomp/snark/Snark.java, org/klomp/snark/Tracker.java, - org/klomp/snark/TrackerClient.java, - org/klomp/snark/bencode/BEncoder.java: Add Tracker, PeerID and - BEncoder. - -2003-05-01 20:17 Mark Wielaard - - * Makefile, org/klomp/snark/ConnectionAcceptor.java, - org/klomp/snark/HttpAcceptor.java, org/klomp/snark/Peer.java, - org/klomp/snark/PeerAcceptor.java, org/klomp/snark/Snark.java: Add - ConnectionAcceptor that handles both PeerAcceptor and HttpAcceptor. - -2003-05-01 18:39 Mark Wielaard - - * org/klomp/snark/PeerCoordinator.java: connected() synchronize on - peers. - -2003-04-28 02:56 Mark Wielaard - - * org/klomp/snark/SnarkShutdown.java: Wait some time before - returning... - -2003-04-28 02:56 Mark Wielaard - - * TODO: More items. - -2003-04-28 02:56 Mark Wielaard - - * org/klomp/snark/Snark.java: Calculate real random ID. - -2003-04-27 Mark Wielaard - - * snark: Initial (0.1) version. diff --git a/thirdparty/snark/Makefile b/thirdparty/snark/Makefile deleted file mode 100644 index a812278d339..00000000000 --- a/thirdparty/snark/Makefile +++ /dev/null @@ -1,85 +0,0 @@ -# Simple Makefile for creating a native binary and a legacy jar file with gcj. - -GCJ=gcj -GCJ_FLAGS=-g -O2 - -#JAVAC=$(GCJ) -C -#JAVAC_FLAGS=$(GCJ_FLAGS) -JAVAC=jikes-classpath -JAVAC_FLAGS=-g -O -source 1.5 - -JAR=fastjar - -PROGRAM=snark -MAINCLASS=org.klomp.snark.Snark - -SOURCES= \ -org/klomp/snark/BitField.java \ -org/klomp/snark/ConnectionAcceptor.java \ -org/klomp/snark/CoordinatorListener.java \ -org/klomp/snark/HttpAcceptor.java \ -org/klomp/snark/MetaInfo.java \ -org/klomp/snark/Message.java \ -org/klomp/snark/Peer.java \ -org/klomp/snark/PeerID.java \ -org/klomp/snark/PeerAcceptor.java \ -org/klomp/snark/PeerCheckerTask.java \ -org/klomp/snark/PeerConnectionIn.java \ -org/klomp/snark/PeerConnectionOut.java \ -org/klomp/snark/PeerListener.java \ -org/klomp/snark/PeerMonitorTask.java \ -org/klomp/snark/PeerCoordinator.java \ -org/klomp/snark/PeerState.java \ -org/klomp/snark/Request.java \ -org/klomp/snark/Snark.java \ -org/klomp/snark/SnarkShutdown.java \ -org/klomp/snark/ShutdownListener.java \ -org/klomp/snark/Storage.java \ -org/klomp/snark/StorageListener.java \ -org/klomp/snark/Tracker.java \ -org/klomp/snark/TrackerClient.java \ -org/klomp/snark/TrackerInfo.java \ -org/klomp/snark/bencode/BEValue.java \ -org/klomp/snark/bencode/BEncoder.java \ -org/klomp/snark/bencode/BDecoder.java \ -org/klomp/snark/bencode/InvalidBEncodingException.java - -STATIC_SOURCES=$(SOURCES) org/klomp/snark/StaticSnark.java -STATIC_MAINCLASS=org.klomp.snark.StaticSnark - -GNOME_SOURCES=$(SOURCES) org/klomp/snark/SnarkGnome.java \ - org/klomp/snark/GnomeInfoWindow.java \ - org/klomp/snark/GnomePeerList.java -GNOME_MAINCLASS=org.klomp.snark.SnarkGnome - -$(PROGRAM): $(SOURCES) - $(GCJ) $(GCJ_FLAGS) --main=$(MAINCLASS) -o $(PROGRAM) $(SOURCES) - -$(PROGRAM)-static: $(STATIC_SOURCES) - $(GCJ) $(GCJ_FLAGS) -static --main=$(STATIC_MAINCLASS) \ - -o $(PROGRAM)-static $(STATIC_SOURCES) - -$(PROGRAM)-gnome: $(GNOME-SOURCES) - $(JAVAC) $(JAVAC_FLAGS) \ - -classpath /usr/share/java/gtk2.8.jar:/usr/share/java/gnome2.12.jar \ - -d dist/classes $(GNOME_SOURCES) - -$(PROGRAM).jar: $(PROGRAM)-classes Manifest - $(JAR) cfm $(PROGRAM).jar Manifest -C dist/classes/ . - -Manifest: - echo "Main-Class: $(MAINCLASS)" > Manifest - -classes: - mkdir dist - mkdir dist/classes - -$(PROGRAM)-classes: classes $(SOURCES) - $(JAVAC) $(JAVAC_FLAGS) -d dist/classes $(SOURCES) - -all: $(PROGRAM) $(PROGRAM)-static $(PROGRAM).jar - -clean: - rm -rf dist Manifest $(PROGRAM) $(PROGRAM)-static $(PROGRAM).jar - -.PHONY : all clean $(PROGRAM)-classes diff --git a/thirdparty/snark/README b/thirdparty/snark/README deleted file mode 100644 index 0567e01d469..00000000000 --- a/thirdparty/snark/README +++ /dev/null @@ -1,141 +0,0 @@ -The Hunting of the Snark Project - BitTorrent Application Suite -0.5 - The Beaver's Lesson (27 June 2003) - - "It's a Snark!" was the sound that first came to their ears, - And seemed almost too good to be true. - Then followed a torrent of laughter and cheers: - Then the ominous words "It's a Boo-" - - -- from The Hunting Of The Snark by Lewis Carroll - -Snark is a client for downloading and sharing files distributed with -the BitTorrent protocol. It is mainly used for exploring the BitTorrent -protocol and experimenting with the the GNU Compiler for Java (gcj). -But it can also be used as a regular BitTorrent Client. - -Snark can also act as a torrent creator, micro http server for delivering -metainfo.torrent files and has an integrated Tracker for making sharing of -files as easy as possible. - -When you give the option --share Snark will automatically -create a .torrent file, start a very simple webserver to distribute -the metainfo.torrent file and a local tracker that other BitTorrent -clients can connect to. - -Distribution ------------- - - Copyright (C) 2003 Mark J. Wielaard - - Snark is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Requirements/Installation -------------------------- - -The GNU Compiler for java (gcj) version 3.3 or later. -(Earlier versions have a faulty SHA message digest implementation.) -On Debian GNU/Linux based distributions just install the gcj-3.3 package. -Edit the GCJ variable in the Makefile if your gcj binary is not gcj-3.3. - -Typing 'make' will create the native snark binary and a snark.jar file -for use with traditional java byte code interpreters. - -It is possible to compile the sources with other java compilers -like jikes or kjc to produce the snark.jar file. Edit the JAVAC and -JAVAC_FLAGS variables on top of the Makefile for this. And type -'make snark.jar' to create a jar file that can be used by traditional -java bytecode interpreters like kaffe: 'kaffe -jar snark.jar'. -You will need at least version 1.1 of kaffe for all functionality to work -correctly ('--share' does not work with older versions). - -When trying out the experimental Gnome frontend you also need the java-gnome -bindings. On Debian GNU/Linux systems install the package libgnome0-java. -You can try it out by typing 'make snark-gnome' and then run 'snark-gnome.sh' -like you would with the normal command line client. - -Running -------- - -To use the program start it with: - -snark [--debug [level]] [--no-commands] [--port ] - [--share (|)] (||) - --debug Shows some extra info and stacktraces. - level How much debug details to show - (defaults to 3, with --debug to 4, highest level is 6). - --no-commands Don't read interactive commands or show usage info. - --port The port to listen on for incomming connections - (if not given defaults to first free port between 6881-6889). - --share Start torrent tracker on address or name. - URL pointing to .torrent metainfo file to download/share. - Either a local .torrent metainfo file to download - or (with --share) a file to share. - A directory with files to share (needs --share). - -Since this is an early beta release there are probably still some bugs -in the program. To help find them run the program with the --debug -option which shows more information on what it going on. You can also give -the level of debug output you want. Zero will give (almost) no output at all. -Everything above debug level 4 is probably to much (only really useful to -see what goes on on the protocol/network level). - -Examples - -- To simple start downloading/sharing a file. - Either download the .torrent file to disk and start snark with: - ./snark somefile.torrent - - Or give it the complete URL: - ./snark http://somehost.example.com/cd-images/bbc-lnx.iso.torrent - -- To start seeding/sharing a local file: - ./snark --share my-host.example.com some-file - - Snark will respond with: - Listening on port: 6881 - Trying to create metainfo torrent for 'some-file' - Creating torrent piece hashes: ++++++++++ - Torrent available on http://my-host.example.com:6881/metainfo.torrent - - You can now point other people to the above URL so they can share - the file with their own BitTorrent client. - -Commands - -While the program is running in text mode you can currently give the -following commands: 'info', 'list' and 'quit'. - -Interactive commands are disabled when the '--no-commands' flag is given. -This is sometimes desireable for running snark in the background. - -More information ----------------- - -- The Evolution of Cooperation - Robert Axelrod - ISBN 0-465-02121-2 - -- The BitTorrent protocol description: - - -- The GNU Compiler for Java (gcj): - - -- java-gnome bindings : - -- The Hunting of the Snark - Lewis Carroll - -Comments welcome - - - Mark Wielaard diff --git a/thirdparty/snark/TODO b/thirdparty/snark/TODO deleted file mode 100644 index cc4f39d5437..00000000000 --- a/thirdparty/snark/TODO +++ /dev/null @@ -1,22 +0,0 @@ -- BEncode - - Byte array length indicator can overflow. - - Support really big BigNums (only 256 chars allowed now) - - Better BEValue toString(). Uses stupid heuristic now for debugging. - - Implemented bencoding. - - Remove application level hack to calculate sha1 hash for metainfo - (But can it be done as efficiently?) - -- Storage - - Check file name filter. - -- TrackerClient - - Support undocumented &numwant= request. - -- Tracker - - Dispose of peers after some time. - -- PeerCoordinator - - Disconnect from other seeds as soon as you are a seed yourself. - -- Text UI - - Make it completely silent. diff --git a/thirdparty/snark/build.xml b/thirdparty/snark/build.xml deleted file mode 100644 index 6921971aa75..00000000000 --- a/thirdparty/snark/build.xml +++ /dev/null @@ -1,214 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/thirdparty/snark/lib/LIBS b/thirdparty/snark/lib/LIBS deleted file mode 100644 index 60ae56308a2..00000000000 --- a/thirdparty/snark/lib/LIBS +++ /dev/null @@ -1,4 +0,0 @@ -gtk2.8.jar -gnome2.12.jar -glib0.2.jar -retroweaver-all-1.2.2.jar diff --git a/thirdparty/snark/lib/manifest-gtk.mf b/thirdparty/snark/lib/manifest-gtk.mf deleted file mode 100644 index f18b6735af0..00000000000 --- a/thirdparty/snark/lib/manifest-gtk.mf +++ /dev/null @@ -1 +0,0 @@ -Main-Class: org.klomp.snark.gtk.SnarkGnome diff --git a/thirdparty/snark/lib/manifest.mf b/thirdparty/snark/lib/manifest.mf deleted file mode 100644 index f04f68fb244..00000000000 --- a/thirdparty/snark/lib/manifest.mf +++ /dev/null @@ -1 +0,0 @@ -Main-Class: org.klomp.snark.cmd.SnarkApplication diff --git a/thirdparty/snark/libs-incl.xml b/thirdparty/snark/libs-incl.xml deleted file mode 100644 index c715442d344..00000000000 --- a/thirdparty/snark/libs-incl.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/thirdparty/snark/snark-gnome.sh b/thirdparty/snark/snark-gnome.sh deleted file mode 100644 index 6687aaaf7fc..00000000000 --- a/thirdparty/snark/snark-gnome.sh +++ /dev/null @@ -1,8 +0,0 @@ -#/bin/sh - -#JAVA=kaffe -JAVA=gij -CLASSPATH=classes:/usr/share/java/gtk.jar:/usr/share/java/gnome.jar -MAINCLASS=org.klomp.snark.SnarkGnome - -${JAVA} -classpath ${CLASSPATH} ${MAINCLASS} $* diff --git a/thirdparty/snark/src/java/org/klomp/snark/BitField.java b/thirdparty/snark/src/java/org/klomp/snark/BitField.java deleted file mode 100644 index 656c5d30d3f..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/BitField.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * BitField - Container of a byte array representing set and unset bits. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -/** - * Container of a byte array representing set and unset bits. - */ -public class BitField -{ - - private final byte[] bitfield; - - private final int size; - - /** - * Creates a new BitField that represents size unset bits. - */ - public BitField (int size) - { - this.size = size; - int arraysize = ((size - 1) / 8) + 1; - bitfield = new byte[arraysize]; - } - - /** - * Creates a new BitField that represents size bits as set by - * the given byte array. This will make a copy of the array. Extra bytes - * will be ignored. - * - * @exception ArrayOutOfBoundsException - * if give byte array is not large enough. - */ - public BitField (byte[] bitfield, int size) - { - this.size = size; - int arraysize = ((size - 1) / 8) + 1; - this.bitfield = new byte[arraysize]; - - // XXX - More correct would be to check that unused bits are - // cleared or clear them explicitly ourselves. - System.arraycopy(bitfield, 0, this.bitfield, 0, arraysize); - } - - /** - * This returns the actual byte array used. Changes to this array effect - * this BitField. Note that some bits at the end of the byte array are - * supposed to be always unset if they represent bits bigger then the size - * of the bitfield. - */ - public byte[] getFieldBytes () - { - return bitfield; - } - - /** - * Return the size of the BitField. The returned value is one bigger then - * the last valid bit number (since bit numbers are counted from zero). - */ - public int size () - { - return size; - } - - /** - * Sets the given bit to true. - * - * @exception IndexOutOfBoundsException - * if bit is smaller then zero bigger then size (inclusive). - */ - public void set (int bit) - { - if (bit < 0 || bit >= size) { - throw new IndexOutOfBoundsException(Integer.toString(bit)); - } - int index = bit / 8; - int mask = 128 >> (bit % 8); - bitfield[index] |= mask; - } - - /** - * Return true if the bit is set or false if it is not. - * - * @exception IndexOutOfBoundsException - * if bit is smaller then zero bigger then size (inclusive). - */ - public boolean get (int bit) - { - if (bit < 0 || bit >= size) { - throw new IndexOutOfBoundsException(Integer.toString(bit)); - } - - int index = bit / 8; - int mask = 128 >> (bit % 8); - return (bitfield[index] & mask) != 0; - } - - @Override - public String toString () - { - // Not very efficient - StringBuffer sb = new StringBuffer("BitField["); - for (int i = 0; i < size; i++) { - if (get(i)) { - sb.append(' '); - sb.append(i); - } - } - sb.append(" ]"); - - return sb.toString(); - } - - public String getHumanReadable() - { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < size; i++) { - if (get(i)) { - sb.append('+'); - } else { - sb.append('-'); - } - } - return sb.toString(); - } -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/ConnectionAcceptor.java b/thirdparty/snark/src/java/org/klomp/snark/ConnectionAcceptor.java deleted file mode 100644 index ddc6d38613b..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/ConnectionAcceptor.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * ConnectionAcceptor - Accepts connections and routes them to sub-acceptors. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Accepts connections on a TCP port and routes them to sub-acceptors. - */ -public class ConnectionAcceptor implements Runnable -{ - private final ServerSocket serverSocket; - - private final HttpAcceptor httpacceptor; - - private final PeerAcceptor peeracceptor; - - private Thread thread; - - private boolean stop; - - public ConnectionAcceptor (ServerSocket serverSocket, - HttpAcceptor httpacceptor, PeerAcceptor peeracceptor) - { - this.serverSocket = serverSocket; - this.httpacceptor = httpacceptor; - this.peeracceptor = peeracceptor; - - stop = false; - } - - public void start () - { - thread = new Thread(this); - thread.start(); - } - - public void halt () - { - stop = true; - - ServerSocket ss = serverSocket; - if (ss != null) { - try { - ss.close(); - } catch (IOException ioe) { - } - } - - Thread t = thread; - if (t != null) { - t.interrupt(); - } - } - - public int getPort () - { - return serverSocket.getLocalPort(); - } - - public void run () - { - while (!stop) { - try { - final Socket socket = serverSocket.accept(); - Thread t = new Thread("Connection-" + socket) { - @Override - public void run () - { - try { - InputStream in = socket.getInputStream(); - OutputStream out = socket.getOutputStream(); - BufferedInputStream bis = new BufferedInputStream( - in); - BufferedOutputStream bos = new BufferedOutputStream( - out); - - // See what kind of connection it is. - if (httpacceptor != null) { - byte[] scratch = new byte[4]; - bis.mark(4); - for (int len = 0; len < 4; len++) { - scratch[len++] = (byte)bis.read(); - } - bis.reset(); - if (scratch[0] == 19 && scratch[1] == 'B' - && scratch[2] == 'i' && scratch[3] == 't') { - peeracceptor.connection(socket, bis, bos); - } else if (scratch[0] == 'G' - && scratch[1] == 'E' && scratch[2] == 'T' - && scratch[3] == ' ') { - httpacceptor.connection(socket, bis, bos); - } - } else { - peeracceptor.connection(socket, bis, bos); - } - } catch (IOException ioe) { - try { - socket.close(); - } catch (IOException ignored) { - } - } - } - }; - t.start(); - } catch (IOException ioe) { - log.log(Level.SEVERE, "Error while accepting", ioe); - stop = true; - } - } - - try { - serverSocket.close(); - } catch (IOException ignored) { - } - } - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.server"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/CoordinatorListener.java b/thirdparty/snark/src/java/org/klomp/snark/CoordinatorListener.java deleted file mode 100644 index 249a27473c8..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/CoordinatorListener.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * CoordinatorListener.java - Callback when a peer changes state - * - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -/** - * Callback used when some peer changes state. - */ -public interface CoordinatorListener -{ - /** - * Called when the PeerCoordinator notices a change in the state of a peer. - */ - void peerChange (PeerCoordinator coordinator, Peer peer); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/HttpAcceptor.java b/thirdparty/snark/src/java/org/klomp/snark/HttpAcceptor.java deleted file mode 100644 index 7f234b30501..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/HttpAcceptor.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * HttpAcceptor - Accepts incomming http connections. Copyright (C) 2003 Mark J. - * Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.Socket; -import java.util.HashMap; -import java.util.Map; -import java.util.StringTokenizer; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class HttpAcceptor -{ - private static final String SNARKHTML = "" - + "" - + "" - + "Snark Client" - + "" - + "

Snark Client

" - + "

Snark is a client for downloading and sharing files distributed with the BitTorrent protocol. It is not a normal webserver.

" - + "

Tracker

" - + "

For more info see The Hunting of the Snark Project

" - + "" + ""; - - private static final byte[] SNARKPAGE; - - private static final String ASCII = "US-ASCII"; - - private static final byte[] CRLF = new byte[] { '\r', '\n' }; - - private static final byte[] HTTP_STATUS; - - private static final byte[] CONTENT_LENGTH; - - private static final byte[] CONTENT_TYPE; - - static { - try { - SNARKPAGE = SNARKHTML.getBytes(ASCII); - - String STATUS = "HTTP/1.0 "; - HTTP_STATUS = STATUS.getBytes(ASCII); - CONTENT_LENGTH = "Content-Length: ".getBytes(ASCII); - CONTENT_TYPE = "Content-Type: ".getBytes(ASCII); - } catch (UnsupportedEncodingException uee) { - // Cannot happen, US-ASCII unknown? - throw new InternalError(uee.toString()); - } - } - - private final Tracker tracker; - - /** - * Creates a HttpAcceptor that can handle torrent metadata of the given - * Tracker. - */ - public HttpAcceptor (Tracker tracker) - { - this.tracker = tracker; - } - - public void connection (Socket sock, BufferedInputStream bis, - BufferedOutputStream bos) throws IOException - { - BufferedReader br = new BufferedReader( - new InputStreamReader(bis, ASCII)); - - String resource = readRequest(br); - log.log(Level.FINE, "HTTP request for: " + resource); - - if (resource != null) { - Map headers = readHeaders(br); - log.log(Level.FINER, headers.toString()); - - if (resource.equals("/")) { - sendData(bos, SNARKPAGE, "text/html"); - } else if (resource.startsWith("/announce")) { - Map params = parseParams(resource); - byte[] response = tracker.handleRequest(sock.getInetAddress(), - sock.getPort(), params); - sendData(bos, response, "application/octet-stream"); - } else if (resource.endsWith(".torrent")) { - MetaInfo info = tracker.getMetaInfo( - resource.substring(1, resource.length() - 8)); - if (info != null) { - byte[] torrent = info.getTorrentData(); - sendData(bos, torrent, "application/x-bittorrent"); - } else { - sendError(bos, 404, "Unable to locate that hash."); - } - } else { - sendError(bos, 404, "Snark Client. Not a real webserver."); - } - } else { - sendError(bos, 500, "Snark Client. Not a real webserver."); - } - - sock.close(); - } - - /** - * Processes an incoming HTTP request. Only handles the most basic GET - * requests. Returns the (URLEncoded) requested resource or null if the - * request wasn't a valid GET request. - */ - private static String readRequest (BufferedReader br) throws IOException - { - String request = br.readLine(); - if (request != null && request.startsWith("GET ")) { - String resource; - int index = request.indexOf(' ', 4); - if (index == -1) { - resource = request.substring(4); - } else { - resource = request.substring(4, index); - } - return resource; - } else { - return null; - } - } - - /** - * Consumes all headers and puts them into a Map mapping header value to - * header key Strings. - */ - private static Map readHeaders (BufferedReader br) - throws IOException - { - Map m = new HashMap(); - String header = br.readLine(); - while (header != null && header.length() != 0) { - header = br.readLine(); - if (header != null && header.length() != 0) { - int index = header.indexOf(": "); - if (index != -1) { - String key = header.substring(0, index); - String value = header.substring(index + 2); - m.put(key, value); - } - } - } - return m; - } - - /** - * Sends a HTTP OK, the necessary headers and the data. - */ - private static void sendData (OutputStream out, byte[] data, - String content_type) throws IOException - { - sendData(out, 200, "OK", data, content_type); - } - - private static void sendData (OutputStream out, int responseCode, - String reason, byte[] data, String content_type) throws IOException - { - log.log(Level.FINER, "HTTP/1.0 " + responseCode + " " + reason + " " - + content_type + " (" + data.length + " bytes)"); - byte[] type = content_type.getBytes(ASCII); - - // Status line - out.write(HTTP_STATUS); - out.write(Integer.toString(responseCode).getBytes(ASCII)); - out.write(' '); - out.write(reason.getBytes(ASCII)); - out.write(CRLF); - - // Entity headers - out.write(CONTENT_LENGTH); - out.write(Integer.toString(data.length).getBytes(ASCII)); - out.write(CRLF); - - out.write(CONTENT_TYPE); - out.write(type); - out.write(CRLF); - - // Start of data - out.write(CRLF); - - out.write(data); - out.flush(); - } - - private static void sendError (OutputStream out, int responseCode, - String reason) throws IOException - { - sendData(out, responseCode, reason, reason.getBytes(ASCII), - "text/plain"); - } - - /** - * Returns a key to value map of the GET request query string parameters. It - * expects a '?' and the urlencoded key=value pairs. Note that the key and - * value are NOT url decoded before putting in the paramaters map. - */ - private static Map parseParams (String request) - { - Map m = new HashMap(); - int index = request.indexOf('?'); - if (index != -1) { - String params = request.substring(index + 1); - StringTokenizer st = new StringTokenizer(params, "&"); - while (st.hasMoreTokens()) { - String token = st.nextToken(); - index = token.indexOf('='); - if (index != -1) { - String key = token.substring(0, index); - String value = token.substring(index + 1); - m.put(key, value); - } - } - } - return m; - } - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.server"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/Message.java b/thirdparty/snark/src/java/org/klomp/snark/Message.java deleted file mode 100644 index 7144c637ea9..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/Message.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Message - A protocol message which can be send through a DataOutputStream. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.DataOutputStream; -import java.io.IOException; - -// Used to queue outgoing connections -// sendMessage() should be used to translate them to wire format. -class Message -{ - final static byte KEEP_ALIVE = -1; - - final static byte CHOKE = 0; - - final static byte UNCHOKE = 1; - - final static byte INTERESTED = 2; - - final static byte UNINTERESTED = 3; - - final static byte HAVE = 4; - - final static byte BITFIELD = 5; - - final static byte REQUEST = 6; - - final static byte PIECE = 7; - - final static byte CANCEL = 8; - - // Not all fields are used for every message. - // KEEP_ALIVE doesn't have a real wire representation - byte type; - - // Used for HAVE, REQUEST, PIECE and CANCEL messages. - int piece; - - // Used for REQUEST, PIECE and CANCEL messages. - int begin; - - int length; - - // Used for PIECE and BITFIELD messages - byte[] data; - - int off; - - int len; - - /** Utility method for sending a message through a DataStream. */ - void sendMessage (DataOutputStream dos) throws IOException - { - // KEEP_ALIVE is special. - if (type == KEEP_ALIVE) { - dos.writeInt(0); - return; - } - - // Calculate the total length in bytes - - // Type is one byte. - int datalen = 1; - - // piece is 4 bytes. - if (type == HAVE || type == REQUEST || type == PIECE || type == CANCEL) { - datalen += 4; - } - - // begin/offset is 4 bytes - if (type == REQUEST || type == PIECE || type == CANCEL) { - datalen += 4; - } - - // length is 4 bytes - if (type == REQUEST || type == CANCEL) { - datalen += 4; - } - - // add length of data for piece or bitfield array. - if (type == BITFIELD || type == PIECE) { - datalen += len; - } - - // Send length - dos.writeInt(datalen); - dos.writeByte(type & 0xFF); - - // Send additional info (piece number) - if (type == HAVE || type == REQUEST || type == PIECE || type == CANCEL) { - dos.writeInt(piece); - } - - // Send additional info (begin/offset) - if (type == REQUEST || type == PIECE || type == CANCEL) { - dos.writeInt(begin); - } - - // Send additional info (length); for PIECE this is implicit. - if (type == REQUEST || type == CANCEL) { - dos.writeInt(length); - } - - // Send actual data - if (type == BITFIELD || type == PIECE) { - dos.write(data, off, len); - } - } - - @Override - public String toString () - { - switch (type) { - case KEEP_ALIVE: - return "KEEP_ALIVE"; - case CHOKE: - return "CHOKE"; - case UNCHOKE: - return "UNCHOKE"; - case INTERESTED: - return "INTERESTED"; - case UNINTERESTED: - return "UNINTERESTED"; - case HAVE: - return "HAVE(" + piece + ")"; - case BITFIELD: - return "BITFIELD"; - case REQUEST: - return "REQUEST(" + piece + "," + begin + "," + length + ")"; - case PIECE: - return "PIECE(" + piece + "," + begin + "," + length + ")"; - case CANCEL: - return "CANCEL(" + piece + "," + begin + "," + length + ")"; - default: - return ""; - } - } -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/MetaInfo.java b/thirdparty/snark/src/java/org/klomp/snark/MetaInfo.java deleted file mode 100644 index 2001723d176..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/MetaInfo.java +++ /dev/null @@ -1,389 +0,0 @@ -/* - * MetaInfo - Holds all information gotten from a torrent file. Copyright (C) - * 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.klomp.snark.bencode.BDecoder; -import org.klomp.snark.bencode.BEValue; -import org.klomp.snark.bencode.BEncoder; -import org.klomp.snark.bencode.InvalidBEncodingException; - -public class MetaInfo -{ - private final String announce; - - private final byte[] info_hash; - - private final String name; - - private final List> files; - - private final List lengths; - - private final int piece_length; - - private final byte[] piece_hashes; - - private final long length; - - private byte[] torrentdata; - - MetaInfo (String announce, String name, List> files, - List lengths, int piece_length, byte[] piece_hashes, long length) - { - this.announce = announce; - this.name = name; - this.files = files; - this.lengths = lengths; - this.piece_length = piece_length; - this.piece_hashes = piece_hashes; - this.length = length; - - this.info_hash = calculateInfoHash(); - } - - /** - * Creates a new MetaInfo from the given InputStream. The InputStream must - * start with a correctly bencoded dictonary describing the torrent. - */ - public MetaInfo (InputStream in) throws IOException - { - this(new BDecoder(in)); - } - - /** - * Creates a new MetaInfo from the given BDecoder. The BDecoder must have a - * complete dictionary describing the torrent. - */ - public MetaInfo (BDecoder be) throws IOException - { - // Note that evaluation order matters here... - this(be.bdecodeMap().getMap()); - } - - /** - * Creates a new MetaInfo from a Map of BEValues and the SHA1 over the - * original bencoded info dictonary (this is a hack, we could reconstruct - * the bencoded stream and recalculate the hash). Will throw a - * InvalidBEncodingException if the given map does not contain a valid - * announce string or info dictonary. - */ - public MetaInfo (Map m) throws InvalidBEncodingException - { - BEValue val = (BEValue)m.get("announce"); - if (val == null) { - throw new InvalidBEncodingException("Missing announce string"); - } - this.announce = val.getString(); - - val = (BEValue)m.get("info"); - if (val == null) { - throw new InvalidBEncodingException("Missing info map"); - } - Map info = val.getMap(); - - val = (BEValue)info.get("name"); - if (val == null) { - throw new InvalidBEncodingException("Missing name string"); - } - name = val.getString(); - - val = (BEValue)info.get("piece length"); - if (val == null) { - throw new InvalidBEncodingException("Missing piece length number"); - } - piece_length = val.getInt(); - - val = (BEValue)info.get("pieces"); - if (val == null) { - throw new InvalidBEncodingException("Missing piece bytes"); - } - piece_hashes = val.getBytes(); - - val = (BEValue)info.get("length"); - if (val != null) { - // Single file case. - length = val.getLong(); - files = null; - lengths = null; - } else { - // Multi file case. - val = (BEValue)info.get("files"); - if (val == null) { - throw new InvalidBEncodingException( - "Missing length number and/or files list"); - } - - List list = val.getList(); - int size = list.size(); - if (size == 0) { - throw new InvalidBEncodingException("zero size files list"); - } - - files = new ArrayList>(size); - lengths = new ArrayList(size); - long l = 0; - for (int i = 0; i < list.size(); i++) { - Map desc = ((BEValue)list.get(i)).getMap(); - val = (BEValue)desc.get("length"); - if (val == null) { - throw new InvalidBEncodingException("Missing length number"); - } - long len = val.getLong(); - lengths.add(len); - l += len; - - val = (BEValue)desc.get("path"); - if (val == null) { - throw new InvalidBEncodingException("Missing path list"); - } - List path_list = val.getList(); - int path_length = path_list.size(); - if (path_length == 0) { - throw new InvalidBEncodingException( - "zero size file path list"); - } - - List file = new ArrayList(path_length); - for (BEValue value : path_list) { - file.add(value.getString()); - } - - files.add(file); - } - length = l; - } - - info_hash = calculateInfoHash(); - } - - /** - * Returns the string representing the URL of the tracker for this torrent. - */ - public String getAnnounce () - { - return announce; - } - - /** - * Returns the original 20 byte SHA1 hash over the bencoded info map. - */ - public byte[] getInfoHash () - { - // XXX - Should we return a clone, just to be sure? - return info_hash; - } - - public String getHexInfoHash () - { - return hexencode(info_hash); - } - - /** - * Returns the piece hashes. Only used by storage so package local. - */ - byte[] getPieceHashes () - { - return piece_hashes; - } - - /** - * Returns the requested name for the file or toplevel directory. If it is a - * toplevel directory name getFiles() will return a non-null List of file - * name hierarchy name. - */ - public String getName () - { - return name; - } - - /** - * Returns a list of lists of file name hierarchies or null if it is a - * single name. It has the same size as the list returned by getLengths(). - */ - public List getFiles () - { - // XXX - Immutable? - return files; - } - - /** - * Returns a list of Longs indication the size of the individual files, or - * null if it is a single file. It has the same size as the list returned by - * getFiles(). - */ - public List getLengths () - { - // XXX - Immutable? - return lengths; - } - - /** - * Returns the number of pieces. - */ - public int getPieces () - { - return piece_hashes.length / 20; - } - - /** - * Return the length of a piece. All pieces are of equal length except for - * the last one (getPieces()-1). - * - * @exception IndexOutOfBoundsException - * when piece is equal to or greater then the number of - * pieces in the torrent. - */ - public int getPieceLength (int piece) - { - int pieces = getPieces(); - if (piece >= 0 && piece < pieces - 1) { - return piece_length; - } else if (piece == pieces - 1) { - return (int)(length - piece * piece_length); - } else { - throw new IndexOutOfBoundsException("no piece: " + piece); - } - } - - /** - * Checks that the given piece has the same SHA1 hash as the given byte - * array. Returns random results or IndexOutOfBoundsExceptions when the - * piece number is unknown. - */ - public boolean checkPiece (int piece, byte[] bs, int off, int length) - { - // Check digest - MessageDigest sha1; - try { - sha1 = MessageDigest.getInstance("SHA"); - } catch (NoSuchAlgorithmException nsae) { - throw new InternalError("No SHA digest available: " + nsae); - } - - sha1.update(bs, off, length); - byte[] hash = sha1.digest(); - for (int i = 0; i < 20; i++) { - if (hash[i] != piece_hashes[20 * piece + i]) { - return false; - } - } - return true; - } - - /** - * Returns the total length of the torrent in bytes. - */ - public long getTotalLength () - { - return length; - } - - @Override - public String toString () - { - return "MetaInfo[info_hash='" + hexencode(info_hash) + "', announce='" - + announce + "', name='" + name + "', files=" + files - + ", #pieces='" + piece_hashes.length / 20 + "', piece_length='" - + piece_length + "', length='" + length + "']"; - } - - /** - * Encode a byte array as a hex encoded string. - */ - private static String hexencode (byte[] bs) - { - StringBuffer sb = new StringBuffer(bs.length * 2); - for (byte element : bs) { - int c = element & 0xFF; - if (c < 16) { - sb.append('0'); - } - sb.append(Integer.toHexString(c)); - } - - return sb.toString(); - } - - /** - * Creates a copy of this MetaInfo that shares everything except the - * announce URL. - */ - public MetaInfo reannounce (String announce) - { - return new MetaInfo(announce, name, files, lengths, piece_length, - piece_hashes, length); - } - - public byte[] getTorrentData () - { - if (torrentdata == null) { - Map m = new HashMap(); - m.put("announce", announce); - Map info = createInfoMap(); - m.put("info", info); - torrentdata = BEncoder.bencode(m); - } - return torrentdata; - } - - private Map createInfoMap () - { - Map info = new HashMap(); - info.put("name", name); - info.put("piece length", piece_length); - info.put("pieces", piece_hashes); - if (files == null) { - info.put("length", new Long(length)); - } else { - List> l = new ArrayList>(); - for (int i = 0; i < files.size(); i++) { - Map file = new HashMap(); - file.put("path", files.get(i)); - file.put("length", lengths.get(i)); - l.add(file); - } - info.put("files", l); - } - return info; - } - - private byte[] calculateInfoHash () - { - Map info = createInfoMap(); - byte[] infoBytes = BEncoder.bencode(info); - try { - MessageDigest digest = MessageDigest.getInstance("SHA"); - return digest.digest(infoBytes); - } catch (NoSuchAlgorithmException nsa) { - throw new InternalError(nsa.toString()); - } - } - -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/Peer.java b/thirdparty/snark/src/java/org/klomp/snark/Peer.java deleted file mode 100644 index 722b118bfd3..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/Peer.java +++ /dev/null @@ -1,393 +0,0 @@ -/* - * Peer - All public information concerning a peer. Copyright (C) 2003 Mark J. - * Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.net.Socket; -import java.util.Arrays; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class Peer implements Comparable -{ - // Identifying property, the peer id of the other side. - private final PeerID peerID; - - private final byte[] my_id; - - private final MetaInfo metainfo; - - // The data in/output streams set during the handshake and used by - // the actual connections. - private DataInputStream din; - - private DataOutputStream dout; - - // Keeps state for in/out connections. Non-null when the handshake - // was successful, the connection setup and runs - PeerState state; - - private boolean deregister = true; - - /** - * Creates a disconnected peer given a PeerID, your own id and the relevant - * MetaInfo. - */ - public Peer (PeerID peerID, byte[] my_id, MetaInfo metainfo) - throws IOException - { - this.peerID = peerID; - this.my_id = my_id; - this.metainfo = metainfo; - } - - /** - * Creates a unconnected peer from the input and output stream got from the - * socket. Note that the complete handshake (which can take some time or - * block indefinitely) is done in the calling Thread to get the remote peer - * id. To completely start the connection call the connect() method. - * - * @exception IOException - * when an error occurred during the handshake. - */ - public Peer (final Socket sock, BufferedInputStream bis, - BufferedOutputStream bos, byte[] my_id, MetaInfo metainfo) - throws IOException - { - this.my_id = my_id; - this.metainfo = metainfo; - - byte[] id = handshake(bis, bos); - this.peerID = new PeerID(id, sock.getInetAddress(), sock.getPort()); - } - - /** - * Returns the id of the peer. - */ - public PeerID getPeerID () - { - return peerID; - } - - /** - * Returns the String representation of the peerID. - */ - @Override - public String toString () - { - return peerID.toString(); - } - - /** - * The hash code of a Peer is the hash code of the peerID. - */ - @Override - public int hashCode () - { - return peerID.hashCode(); - } - - /** - * Two Peers are equal when they have the same PeerID. All other properties - * are ignored. - */ - @Override - public boolean equals (Object o) - { - if (o instanceof Peer) { - Peer p = (Peer)o; - return peerID.equals(p.peerID); - } else { - return false; - } - } - - /** - * Compares the PeerIDs. - */ - public int compareTo (Peer p) - { - return peerID.compareTo(p.peerID); - } - - /** - * Runs the connection to the other peer. This method does not return until - * the connection is terminated. - * - * When the connection is correctly started the connected() method of the - * given PeerListener is called. If the connection ends or the connection - * could not be setup correctly the disconnected() method is called. - * - * If the given BitField is non-null it is send to the peer as first - * message. - */ - public void runConnection (PeerListener listener, BitField bitfield) - { - if (state != null) { - throw new IllegalStateException("Peer already started"); - } - - try { - // Do we need to handshake? - if (din == null) { - Socket sock = new Socket(peerID.getAddress(), peerID.getPort()); - BufferedInputStream bis = new BufferedInputStream( - sock.getInputStream()); - BufferedOutputStream bos = new BufferedOutputStream( - sock.getOutputStream()); - byte[] id = handshake(bis, bos); - byte[] expected_id = peerID.getID(); - if (!Arrays.equals(expected_id, id)) { - throw new IOException("Unexpected peerID '" - + PeerID.idencode(id) + "' expected '" - + PeerID.idencode(expected_id) + "'"); - } - } - - PeerConnectionIn in = new PeerConnectionIn(this, din); - PeerConnectionOut out = new PeerConnectionOut(this, dout); - PeerState s = new PeerState(this, listener, metainfo, in, out); - - // Send our bitmap - if (bitfield != null) { - s.out.sendBitfield(bitfield); - } - - // We are up and running! - state = s; - listener.connected(this); - - // Use this thread for running the incomming connection. - // The outgoing connection has created its own Thread. - s.in.run(); - } catch (IOException eofe) { - log.log(Level.FINE, "Peer connection to " + peerID.getAddress() + " failed ", eofe); - } catch (Throwable t) { - log.log(Level.SEVERE, "Peer connection failed " + toString(), t); - t.printStackTrace(); - } finally { - if (deregister) { - listener.disconnected(this); - } - } - } - - /** - * Sets DataIn/OutputStreams, does the handshake and returns the id reported - * by the other side. - */ - private byte[] handshake (BufferedInputStream bis, BufferedOutputStream bos) - throws IOException - { - din = new DataInputStream(bis); - dout = new DataOutputStream(bos); - - // Handshake write - header - dout.write(19); - dout.write("BitTorrent protocol".getBytes("UTF-8")); - // Handshake write - zeros - byte[] zeros = new byte[8]; - dout.write(zeros); - // Handshake write - metainfo hash - byte[] shared_hash = metainfo.getInfoHash(); - dout.write(shared_hash); - // Handshake write - peer id - dout.write(my_id); - dout.flush(); - - // Handshake read - header - byte b = din.readByte(); - if (b != 19) { - throw new IOException("Handshake failure, expected 19, got " - + (b & 0xff)); - } - - byte[] bs = new byte[19]; - din.readFully(bs); - String bittorrentProtocol = new String(bs, "UTF-8"); - if (!"BitTorrent protocol".equals(bittorrentProtocol)) { - throw new IOException("Handshake failure, expected " - + "'Bittorrent protocol', got '" + bittorrentProtocol + "'"); - } - - // Handshake read - zeros - din.readFully(zeros); - - // Handshake read - metainfo hash - bs = new byte[20]; - din.readFully(bs); - if (!Arrays.equals(shared_hash, bs)) { - throw new IOException("Unexpected MetaInfo hash"); - } - - // Handshake read - peer id - din.readFully(bs); - return bs; - } - - public boolean isConnected () - { - return state != null; - } - - /** - * Disconnects this peer if it was connected. If deregister is true, - * PeerListener.disconnected() will be called when the connection is - * completely terminated. Otherwise the connection is silently terminated. - */ - public void disconnect (boolean deregister) - { - // Both in and out connection will call this. - this.deregister = deregister; - disconnect(); - } - - void disconnect () - { - PeerState s = state; - if (s != null) { - state = null; - - PeerConnectionIn in = s.in; - if (in != null) { - in.disconnect(); - } - PeerConnectionOut out = s.out; - if (out != null) { - out.disconnect(); - } - } - } - - /** - * Tell the peer we have another piece. - */ - public void have (int piece) - { - PeerState s = state; - if (s != null) { - s.havePiece(piece); - } - } - - /** - * Whether or not the peer is interested in pieces we have. Returns false if - * not connected. - */ - public boolean isInterested () - { - PeerState s = state; - return (s != null) && s.interested; - } - - /** - * Sets whether or not we are interested in pieces from this peer. Defaults - * to false. When interest is true and this peer unchokes us then we start - * downloading from it. Has no effect when not connected. - */ - public void setInteresting (boolean interest) - { - PeerState s = state; - if (s != null) { - s.setInteresting(interest); - } - } - - /** - * Whether or not the peer has pieces we want from it. Returns false if not - * connected. - */ - public boolean isInteresting () - { - PeerState s = state; - return (s != null) && s.interesting; - } - - /** - * Sets whether or not we are choking the peer. Defaults to true. When choke - * is false and the peer requests some pieces we upload them, otherwise - * requests of this peer are ignored. - */ - public void setChoking (boolean choke) - { - PeerState s = state; - if (s != null) { - s.setChoking(choke); - } - } - - /** - * Whether or not we are choking the peer. Returns true when not connected. - */ - public boolean isChoking () - { - PeerState s = state; - return (s == null) || s.choking; - } - - /** - * Whether or not the peer choked us. Returns true when not connected. - */ - public boolean isChoked () - { - PeerState s = state; - return (s == null) || s.choked; - } - - /** - * Returns the number of bytes that have been downloaded. Can be reset to - * zero with resetCounters()/ - */ - public long getDownloaded () - { - PeerState s = state; - return (s != null) ? s.downloaded : 0; - } - - /** - * Returns the number of bytes that have been uploaded. Can be reset to zero - * with resetCounters()/ - */ - public long getUploaded () - { - PeerState s = state; - return (s != null) ? s.uploaded : 0; - } - - /** - * Resets the downloaded and uploaded counters to zero. - */ - public void resetCounters () - { - PeerState s = state; - if (s != null) { - s.downloaded = 0; - s.uploaded = 0; - } - } - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.peer"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/PeerAcceptor.java b/thirdparty/snark/src/java/org/klomp/snark/PeerAcceptor.java deleted file mode 100644 index f0794fc5ee3..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/PeerAcceptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * PeerAcceptor - Accepts incomming connections from peers. Copyright (C) 2003 - * Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.net.Socket; - -/** - * Accepts incomming connections from peers. The ConnectionAcceptor will call - * the connection() method when it detects an incomming BT protocol connection. - * The PeerAcceptor will then create a new peer if the PeerCoordinator wants - * more peers. - */ -public class PeerAcceptor -{ - private final PeerCoordinator coordinator; - - public PeerAcceptor (PeerCoordinator coordinator) - { - this.coordinator = coordinator; - } - - public void connection (Socket socket, BufferedInputStream bis, - BufferedOutputStream bos) throws IOException - { - if (coordinator.needPeers()) { - Peer peer = new Peer(socket, bis, bos, coordinator.getID(), - coordinator.getMetaInfo()); - coordinator.addPeer(peer); - } else { - socket.close(); - } - } -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/PeerCheckerTask.java b/thirdparty/snark/src/java/org/klomp/snark/PeerCheckerTask.java deleted file mode 100644 index 410a7c14f13..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/PeerCheckerTask.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * PeerCheckTasks - TimerTask that checks for good/bad up/downloaders. Copyright - * (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.TimerTask; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * TimerTask that checks for good/bad up/downloader. Works together with the - * PeerCoordinator to select which Peers get (un)choked. - */ -class PeerCheckerTask extends TimerTask -{ - private static final long KILOPERSECOND = 1024 * (PeerCoordinator.CHECK_PERIOD / 1000); - - private final PeerCoordinator coordinator; - - PeerCheckerTask (PeerCoordinator coordinator) - { - this.coordinator = coordinator; - } - - @Override - public void run () - { - synchronized (coordinator.peers) { - // Calculate total uploading and worst downloader. - long worstdownload = Long.MAX_VALUE; - Peer worstDownloader = null; - - int peers = 0; - int uploaders = 0; - int downloaders = 0; - int interested = 0; - int interesting = 0; - int choking = 0; - int choked = 0; - - long uploaded = 0; - long downloaded = 0; - - // Keep track of peers we remove now, - // we will add them back to the end of the list. - List removed = new ArrayList(); - - Iterator it = coordinator.peers.iterator(); - while (it.hasNext()) { - Peer peer = (Peer)it.next(); - - // Remove dying peers - if (!peer.isConnected()) { - it.remove(); - continue; - } - - peers++; - - if (!peer.isChoking()) { - uploaders++; - } - if (!peer.isChoked() && peer.isInteresting()) { - downloaders++; - } - if (peer.isInterested()) { - interested++; - } - if (peer.isInteresting()) { - interesting++; - } - if (peer.isChoking()) { - choking++; - } - if (peer.isChoked()) { - choked++; - } - - // XXX - We should calculate the up/download rate a bit - // more intelligently - long upload = peer.getUploaded(); - uploaded += upload; - long download = peer.getDownloaded(); - downloaded += download; - peer.resetCounters(); - - log.log(Level.FINEST, peer + ":" + " ul: " + upload - / KILOPERSECOND + " dl: " + download / KILOPERSECOND - + " i: " + peer.isInterested() + " I: " - + peer.isInteresting() + " c: " + peer.isChoking() + " C: " - + peer.isChoked()); - - // If we are at our max uploaders and we have lots of other - // interested peers try to make some room. - // (Note use of coordinator.uploaders) - if (coordinator.uploaders >= PeerCoordinator.MAX_UPLOADERS - && interested > PeerCoordinator.MAX_UPLOADERS - && !peer.isChoking()) { - // Check if it still wants pieces from us. - if (!peer.isInterested()) { - log.log(Level.FINER, "Choke uninterested peer: " + peer); - peer.setChoking(true); - uploaders--; - coordinator.uploaders--; - - // Put it at the back of the list - it.remove(); - removed.add(peer); - } else if (peer.isChoked()) { - // If they are choking us make someone else a downloader - log.log(Level.FINEST, "Choke choking peer: " + peer); - peer.setChoking(true); - uploaders--; - coordinator.uploaders--; - - // Put it at the back of the list - it.remove(); - removed.add(peer); - } else if (peer.isInteresting() && !peer.isChoked() - && download == 0) { - // We are downloading but didn't receive anything... - log.log(Level.FINEST, - "Choke downloader that doesn't deliver:" + peer); - peer.setChoking(true); - uploaders--; - coordinator.uploaders--; - - // Put it at the back of the list - it.remove(); - removed.add(peer); - } else if (!peer.isChoking() && download < worstdownload) { - // Make sure download is good if we are uploading - worstdownload = download; - worstDownloader = peer; - } - } - } - - // Resync actual uploaders value - // (can shift a bit by disconnecting peers) - coordinator.uploaders = uploaders; - - // Remove the worst downloader if needed. - if (uploaders >= PeerCoordinator.MAX_UPLOADERS - && interested > PeerCoordinator.MAX_UPLOADERS - && worstDownloader != null) { - log.log(Level.FINEST, "Choke worst downloader: " - + worstDownloader); - - worstDownloader.setChoking(true); - coordinator.uploaders--; - - // Put it at the back of the list - coordinator.peers.remove(worstDownloader); - removed.add(worstDownloader); - } - - // Optimistically unchoke a peer - coordinator.unchokePeer(); - - // Put peers back at the end of the list that we removed earlier. - coordinator.peers.addAll(removed); - } - } - - protected static final Logger log = Logger.getLogger("org.klomp.snark.peer"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/PeerConnectionIn.java b/thirdparty/snark/src/java/org/klomp/snark/PeerConnectionIn.java deleted file mode 100644 index b9b2dffb9d3..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/PeerConnectionIn.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * PeerConnectionIn - Handles incomming messages and hands them to PeerState. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.DataInputStream; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -class PeerConnectionIn implements Runnable -{ - private final Peer peer; - - private final DataInputStream din; - - private Thread thread; - - private boolean quit; - - public PeerConnectionIn (Peer peer, DataInputStream din) - { - this.peer = peer; - this.din = din; - quit = false; - } - - void disconnect () - { - if (quit == true) { - return; - } - - quit = true; - Thread t = thread; - if (t != null) { - t.interrupt(); - } - } - - public void run () - { - thread = Thread.currentThread(); - try { - PeerState ps = peer.state; - while (!quit && ps != null) { - // Common variables used for some messages. - int piece; - int begin; - int len; - - // Wait till we hear something... - // The length of a complete message in bytes. - int i = din.readInt(); - if (i < 0) { - throw new IOException("Unexpected length prefix: " + i); - } - - if (i == 0) { - ps.keepAliveMessage(); - continue; - } - - byte b = din.readByte(); - Message m = new Message(); - m.type = b; - switch (b) { - case 0: - ps.chokeMessage(true); - break; - case 1: - ps.chokeMessage(false); - break; - case 2: - ps.interestedMessage(true); - break; - case 3: - ps.interestedMessage(false); - break; - case 4: - piece = din.readInt(); - ps.haveMessage(piece); - break; - case 5: - byte[] bitmap = new byte[i - 1]; - din.readFully(bitmap); - ps.bitfieldMessage(bitmap); - break; - case 6: - piece = din.readInt(); - begin = din.readInt(); - len = din.readInt(); - ps.requestMessage(piece, begin, len); - break; - case 7: - piece = din.readInt(); - begin = din.readInt(); - len = i - 9; - Request req = ps.getOutstandingRequest(piece, begin, len); - byte[] piece_bytes; - if (req != null) { - piece_bytes = req.bs; - din.readFully(piece_bytes, begin, len); - ps.pieceMessage(req); - } else { - // XXX - Consume but throw away afterwards. - piece_bytes = new byte[len]; - din.readFully(piece_bytes); - } - break; - case 8: - piece = din.readInt(); - begin = din.readInt(); - len = din.readInt(); - ps.cancelMessage(piece, begin, len); - break; - default: - byte[] bs = new byte[i - 1]; - din.readFully(bs); - ps.unknownMessage(b, bs); - } - } - } catch (IOException ioe) { - // Ignore, probably the other side closed connection. - } catch (Throwable t) { - log.log(Level.SEVERE, peer + " failed", t); - } finally { - peer.disconnect(); - } - } - - protected static final Logger log = Logger.getLogger("org.klomp.snark.peer"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/PeerConnectionOut.java b/thirdparty/snark/src/java/org/klomp/snark/PeerConnectionOut.java deleted file mode 100644 index a139e9e8f61..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/PeerConnectionOut.java +++ /dev/null @@ -1,319 +0,0 @@ -/* - * PeerConnectionOut - Keeps a queue of outgoing messages and delivers them. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -class PeerConnectionOut implements Runnable -{ - private final Peer peer; - - private final DataOutputStream dout; - - private Thread thread; - - private boolean quit; - - private List sendQueue = new ArrayList(); - - public PeerConnectionOut (Peer peer, DataOutputStream dout) - { - this.peer = peer; - this.dout = dout; - - quit = false; - thread = new Thread(this); - thread.start(); - } - - /** - * Continuesly monitors for more outgoing messages that have to be send. - * Stops if quit is true of an IOException occurs. - */ - public void run () - { - try { - while (!quit) { - Message m = null; - PeerState state = null; - synchronized (sendQueue) { - while (!quit && sendQueue.isEmpty()) { - try { - // Make sure everything will reach the other side. - dout.flush(); - - // Wait till more data arrives. - sendQueue.wait(); - } catch (InterruptedException ie) { - /* ignored */ - } - } - state = peer.state; - if (!quit && state != null) { - // Piece messages are big. So if there are other - // (control) messages make sure they are send first. - // Also remove request messages from the queue if - // we are currently being choked to prevent them from - // being send even if we get unchoked a little later. - // (Since we will resent them anyway in that case.) - // And remove piece messages if we are choking. - Iterator it = sendQueue.iterator(); - while (m == null && it.hasNext()) { - Message nm = (Message)it.next(); - if (nm.type == Message.PIECE) { - if (state.choking) { - it.remove(); - } - nm = null; - } else if (nm.type == Message.REQUEST - && state.choked) { - it.remove(); - nm = null; - } - - if (m == null && nm != null) { - m = nm; - it.remove(); - } - } - if (m == null && sendQueue.size() > 0) { - m = sendQueue.remove(0); - } - } - } - if (m != null) { - log.log(Level.ALL, "Send " + peer + ": " + m); - m.sendMessage(dout); - - // Remove all piece messages after sending a choke message. - if (m.type == Message.CHOKE) { - removeMessage(Message.PIECE); - } - - // XXX - Should also register overhead... - if (m.type == Message.PIECE) { - state.uploaded(m.len); - } - - m = null; - } - } - } catch (IOException ioe) { - // Ignore, probably other side closed connection. - } catch (Throwable t) { - log.log(Level.SEVERE, peer + " failed", t); - } finally { - quit = true; - peer.disconnect(); - } - } - - public void disconnect () - { - synchronized (sendQueue) { - if (quit == true) { - return; - } - - quit = true; - thread.interrupt(); - - sendQueue.clear(); - sendQueue.notify(); - } - } - - /** - * Adds a message to the sendQueue and notifies the method waiting on the - * sendQueue to change. - */ - private void addMessage (Message m) - { - synchronized (sendQueue) { - sendQueue.add(m); - sendQueue.notify(); - } - } - - /** - * Removes a particular message type from the queue. - * - * @param type - * the Message type to remove. - * @returns true when a message of the given type was removed, false - * otherwise. - */ - private boolean removeMessage (int type) - { - boolean removed = false; - synchronized (sendQueue) { - Iterator it = sendQueue.iterator(); - while (it.hasNext()) { - Message m = (Message)it.next(); - if (m.type == type) { - it.remove(); - removed = true; - } - } - } - return removed; - } - - void sendAlive () - { - Message m = new Message(); - m.type = Message.KEEP_ALIVE; - addMessage(m); - } - - void sendChoke (boolean choke) - { - // We cancel the (un)choke but keep PIECE messages. - // PIECE messages are purged if a choke is actually send. - synchronized (sendQueue) { - int inverseType = choke ? Message.UNCHOKE : Message.CHOKE; - if (!removeMessage(inverseType)) { - Message m = new Message(); - if (choke) { - m.type = Message.CHOKE; - } else { - m.type = Message.UNCHOKE; - } - addMessage(m); - } - } - } - - void sendInterest (boolean interest) - { - synchronized (sendQueue) { - int inverseType = interest ? Message.UNINTERESTED - : Message.INTERESTED; - if (!removeMessage(inverseType)) { - Message m = new Message(); - if (interest) { - m.type = Message.INTERESTED; - } else { - m.type = Message.UNINTERESTED; - } - addMessage(m); - } - } - } - - void sendHave (int piece) - { - Message m = new Message(); - m.type = Message.HAVE; - m.piece = piece; - addMessage(m); - } - - void sendBitfield (BitField bitfield) - { - Message m = new Message(); - m.type = Message.BITFIELD; - m.data = bitfield.getFieldBytes(); - m.off = 0; - m.len = m.data.length; - addMessage(m); - } - - void sendRequests (List requests) - { - Iterator it = requests.iterator(); - while (it.hasNext()) { - Request req = (Request)it.next(); - sendRequest(req); - } - } - - void sendRequest (Request req) - { - Message m = new Message(); - m.type = Message.REQUEST; - m.piece = req.piece; - m.begin = req.off; - m.length = req.len; - addMessage(m); - } - - void sendPiece (int piece, int begin, int length, byte[] bytes) - { - Message m = new Message(); - m.type = Message.PIECE; - m.piece = piece; - m.begin = begin; - m.length = length; - m.data = bytes; - m.off = begin; - m.len = length; - addMessage(m); - } - - void sendCancel (Request req) - { - // See if it is still in our send queue - synchronized (sendQueue) { - Iterator it = sendQueue.iterator(); - while (it.hasNext()) { - Message m = (Message)it.next(); - if (m.type == Message.REQUEST && m.piece == req.piece - && m.begin == req.off && m.length == req.len) { - it.remove(); - } - } - } - - // Always send, just to be sure it it is really canceled. - Message m = new Message(); - m.type = Message.CANCEL; - m.piece = req.piece; - m.begin = req.off; - m.length = req.len; - addMessage(m); - } - - // Called by the PeerState when the other side doesn't want this - // request to be handled anymore. Removes any pending Piece Message - // from out send queue. - void cancelRequest (int piece, int begin, int length) - { - synchronized (sendQueue) { - Iterator it = sendQueue.iterator(); - while (it.hasNext()) { - Message m = (Message)it.next(); - if (m.type == Message.PIECE && m.piece == piece - && m.begin == begin && m.length == length) { - it.remove(); - } - } - } - } - - protected static final Logger log = Logger.getLogger("org.klomp.snark.peer"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/PeerCoordinator.java b/thirdparty/snark/src/java/org/klomp/snark/PeerCoordinator.java deleted file mode 100644 index 8d8063c2778..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/PeerCoordinator.java +++ /dev/null @@ -1,498 +0,0 @@ -/* - * PeerCoordinator - Coordinates which peers do what (up and downloading). - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Timer; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Coordinates what peer does what. - */ -public class PeerCoordinator implements PeerListener -{ - final MetaInfo metainfo; - - final Storage storage; - - // package local for access by CheckDownLoadersTask - final static long CHECK_PERIOD = 20 * 1000; // 20 seconds - - final static int MAX_CONNECTIONS = 24; - - final static int MAX_UPLOADERS = 4; - - // Approximation of the number of current uploaders. - // Resynced by PeerChecker once in a while. - int uploaders = 0; - - // final static int MAX_DOWNLOADERS = MAX_CONNECTIONS; - // int downloaders = 0; - - private long uploaded; - - private long downloaded; - - // synchronize on this when changing peers or downloaders - public final List peers = new ArrayList(); - - /** Timer to handle all periodical tasks. */ - private final Timer timer = new Timer(true); - - private final byte[] id; - - // Some random wanted pieces - private final List wantedPieces; - - private boolean halted = false; - - private final CoordinatorListener listener; - - private TrackerClient client; - - public PeerCoordinator (byte[] id, MetaInfo metainfo, Storage storage, - CoordinatorListener listener) - { - this.id = id; - this.metainfo = metainfo; - this.storage = storage; - this.listener = listener; - - // Make a random list of piece numbers - wantedPieces = new ArrayList(); - BitField bitfield = storage.getBitField(); - for (int i = 0; i < metainfo.getPieces(); i++) { - if (!bitfield.get(i)) { - wantedPieces.add(i); - } - } - Collections.shuffle(wantedPieces); - - // Install a timer to check the uploaders. - timer.schedule(new PeerCheckerTask(this), CHECK_PERIOD, CHECK_PERIOD); - } - - public void setTracker (TrackerClient client) - { - this.client = client; - } - - public byte[] getID () - { - return id; - } - - public boolean completed () - { - return storage.complete(); - } - - public int getPeers () - { - synchronized (peers) { - return peers.size(); - } - } - - /** - * Returns how many bytes are still needed to get the complete file. - */ - public long getLeft () - { - // XXX - Only an approximation. - return storage.needed() * metainfo.getPieceLength(0); - } - - /** - * Returns the total number of uploaded bytes of all peers. - */ - public long getUploaded () - { - return uploaded; - } - - /** - * Returns the total number of downloaded bytes of all peers. - */ - public long getDownloaded () - { - return downloaded; - } - - public MetaInfo getMetaInfo () - { - return metainfo; - } - - public boolean needPeers () - { - synchronized (peers) { - return !halted && peers.size() < MAX_CONNECTIONS; - } - } - - public void halt () - { - halted = true; - synchronized (peers) { - // Stop peer checker task. - timer.cancel(); - - // Stop peers. - Iterator it = peers.iterator(); - while (it.hasNext()) { - Peer peer = (Peer)it.next(); - peer.disconnect(); - it.remove(); - } - } - } - - public void connected (Peer peer) - { - if (halted) { - peer.disconnect(false); - return; - } - - synchronized (peers) { - if (peerIDInList(peer.getPeerID(), peers)) { - log.log(Level.FINER, "Already connected to: " + peer); - peer.disconnect(false); // Don't deregister this - // connection/peer. - } else { - log.log(Level.FINER, "New connection to peer: " + peer); - - // Add it to the beginning of the list. - // And try to optimistically make it a uploader. - peers.add(0, peer); - unchokePeer(); - - if (listener != null) { - listener.peerChange(this, peer); - } - } - } - } - - private static boolean peerIDInList (PeerID pid, List peers) - { - Iterator it = peers.iterator(); - while (it.hasNext()) { - if (pid.sameID(((Peer)it.next()).getPeerID())) { - return true; - } - } - return false; - } - - public void addPeer (final Peer peer) - { - if (halted) { - peer.disconnect(false); - return; - } - - boolean need_more; - synchronized (peers) { - need_more = !peer.isConnected() && peers.size() < MAX_CONNECTIONS; - } - - if (need_more) { - // Run the peer with us as listener and the current bitfield. - final PeerListener listener = this; - final BitField bitfield = storage.getBitField(); - Runnable r = new Runnable() { - public void run () - { - peer.runConnection(listener, bitfield); - } - }; - String threadName = peer.toString(); - new Thread(r, threadName).start(); - } else if (log.getLevel().intValue() <= Level.FINER.intValue()) { - if (peer.isConnected()) { - log.log(Level.FINER, "Add peer already connected: " + peer); - } else { - log.log(Level.FINER, "MAX_CONNECTIONS = " + MAX_CONNECTIONS - + " not accepting extra peer: " + peer); - } - } - } - - // (Optimistically) unchoke. Should be called with peers synchronized - void unchokePeer () - { - // linked list will contain all interested peers that we choke. - // At the start are the peers that have us unchoked at the end the - // other peer that are interested, but are choking us. - List interested = new LinkedList(); - Iterator it = peers.iterator(); - while (it.hasNext()) { - Peer peer = (Peer)it.next(); - if (uploaders < MAX_UPLOADERS && peer.isChoking() - && peer.isInterested()) { - if (!peer.isChoked()) { - interested.add(0, peer); - } else { - interested.add(peer); - } - } - } - - while (uploaders < MAX_UPLOADERS && interested.size() > 0) { - Peer peer = interested.remove(0); - log.log(Level.FINER, "Unchoke: " + peer); - peer.setChoking(false); - uploaders++; - // Put peer back at the end of the list. - peers.remove(peer); - peers.add(peer); - } - } - - public byte[] getBitMap () - { - return storage.getBitField().getFieldBytes(); - } - - /** - * Returns true if we don't have the given piece yet. - */ - public boolean gotHave (Peer peer, int piece) - { - if (listener != null) { - listener.peerChange(this, peer); - } - - synchronized (wantedPieces) { - return wantedPieces.contains(new Integer(piece)); - } - } - - /** - * Returns true if the given bitfield contains at least one piece we are - * interested in. - */ - public boolean gotBitField (Peer peer, BitField bitfield) - { - if (listener != null) { - listener.peerChange(this, peer); - } - - synchronized (wantedPieces) { - Iterator it = wantedPieces.iterator(); - while (it.hasNext()) { - int i = ((Integer)it.next()).intValue(); - if (bitfield.get(i)) { - return true; - } - } - } - return false; - } - - /** - * Returns one of pieces in the given BitField that is still wanted or -1 if - * none of the given pieces are wanted. - */ - public int wantPiece (Peer peer, BitField havePieces) - { - if (halted) { - return -1; - } - - synchronized (wantedPieces) { - Integer piece = null; - Iterator it = wantedPieces.iterator(); - while (piece == null && it.hasNext()) { - Integer i = (Integer)it.next(); - if (havePieces.get(i.intValue())) { - it.remove(); - piece = i; - } - } - - if (piece == null) { - return -1; - } - - // We add it back at the back of the list. It will be removed - // if gotPiece is called later. This means that the last - // couple of pieces might very well be asked from multiple - // peers but that is OK. - wantedPieces.add(piece); - - return piece.intValue(); - } - } - - /** - * Returns a byte array containing the requested piece or null of the piece - * is unknown. - */ - public byte[] gotRequest (Peer peer, int piece) - throws IOException - { - if (halted) { - return null; - } - - try { - return storage.getPiece(piece); - } catch (IOException ioe) { - Snark.abort("Error reading storage", ioe); - return null; // Never reached. - } - } - - /** - * Called when a peer has uploaded some bytes of a piece. - */ - public void uploaded (Peer peer, int size) - { - uploaded += size; - - if (listener != null) { - listener.peerChange(this, peer); - } - } - - /** - * Called when a peer has downloaded some bytes of a piece. - */ - public void downloaded (Peer peer, int size) - { - downloaded += size; - - if (listener != null) { - listener.peerChange(this, peer); - } - } - - /** - * Returns false if the piece is no good (according to the hash). In that - * case the peer that supplied the piece should probably be blacklisted. - */ - public boolean gotPiece (Peer peer, int piece, byte[] bs) - throws IOException - { - if (halted) { - return true; // We don't actually care anymore. - } - - synchronized (wantedPieces) { - Integer p = new Integer(piece); - if (!wantedPieces.contains(p)) { - log.log(Level.FINER, peer + " piece " + piece - + " no longer needed"); - - // No need to announce have piece to peers. - // Assume we got a good piece, we don't really care anymore. - return true; - } - - try { - if (storage.putPiece(piece, bs)) { - log.log(Level.FINER, "Recv p" + piece + " " + peer); - } else { - // Oops. We didn't actually download this then... :( - downloaded -= metainfo.getPieceLength(piece); - log.log(Level.INFO, "Got BAD piece " + piece + " from " - + peer); - return false; // No need to announce BAD piece to peers. - } - } catch (IOException ioe) { - Snark.abort("Error writing storage", ioe); - } - wantedPieces.remove(p); - } - - // Announce to the world we have it! - synchronized (peers) { - Iterator it = peers.iterator(); - while (it.hasNext()) { - Peer p = (Peer)it.next(); - if (p.isConnected()) { - p.have(piece); - } - } - } - - if (completed()) { - client.interrupt(); - } - return true; - } - - public void gotChoke (Peer peer, boolean choke) - { - log.log(Level.FINER, "Got choke(" + choke + "): " + peer); - - if (listener != null) { - listener.peerChange(this, peer); - } - } - - public void gotInterest (Peer peer, boolean interest) - { - if (interest) { - synchronized (peers) { - if (uploaders < MAX_UPLOADERS) { - if (peer.isChoking()) { - uploaders++; - peer.setChoking(false); - log.log(Level.FINER, "Unchoke: " + peer); - } - } - } - } - - if (listener != null) { - listener.peerChange(this, peer); - } - } - - public void disconnected (Peer peer) - { - log.log(Level.FINER, "Disconnected " + peer); - - synchronized (peers) { - // Make sure it is no longer in our lists - if (peers.remove(peer)) { - // Unchoke some random other peer - unchokePeer(); - } - } - - if (listener != null) { - listener.peerChange(this, peer); - } - } - - protected static final Logger log = Logger.getLogger("org.klomp.snark.peer"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/PeerID.java b/thirdparty/snark/src/java/org/klomp/snark/PeerID.java deleted file mode 100644 index 32351c06497..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/PeerID.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * PeerID - All public information concerning a peer. Copyright (C) 2003 Mark J. - * Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Map; - -import org.klomp.snark.bencode.BDecoder; -import org.klomp.snark.bencode.BEValue; -import org.klomp.snark.bencode.InvalidBEncodingException; - -public class PeerID implements Comparable -{ - private final byte[] id; - - private final InetAddress address; - - private final int port; - - private final int hash; - - public PeerID (byte[] id, InetAddress address, int port) - { - this.id = id; - this.address = address; - this.port = port; - - hash = calculateHash(); - } - - /** - * Creates a PeerID from a BDecoder. - */ - public PeerID (BDecoder be) throws IOException - { - this(be.bdecodeMap().getMap()); - } - - /** - * Creates a PeerID from a Map containing BEncoded peer id, ip and port. - */ - public PeerID (Map m) - throws InvalidBEncodingException, UnknownHostException - { - BEValue bevalue = (BEValue)m.get("peer id"); - if (bevalue == null) { - throw new InvalidBEncodingException("peer id missing"); - } - id = bevalue.getBytes(); - - bevalue = (BEValue)m.get("ip"); - if (bevalue == null) { - throw new InvalidBEncodingException("ip missing"); - } - address = InetAddress.getByName(bevalue.getString()); - - bevalue = (BEValue)m.get("port"); - if (bevalue == null) { - throw new InvalidBEncodingException("port missing"); - } - port = bevalue.getInt(); - - hash = calculateHash(); - } - - public byte[] getID () - { - return id; - } - - public InetAddress getAddress () - { - return address; - } - - public int getPort () - { - return port; - } - - private int calculateHash () - { - int b = 0; - for (byte element : id) { - b ^= element; - } - return (b ^ address.hashCode()) ^ port; - } - - /** - * The hash code of a PeerID is the exclusive or of all id bytes. - */ - @Override - public int hashCode () - { - return hash; - } - - /** - * Returns true if and only if this peerID and the given peerID have the - * same 20 bytes as ID. - */ - public boolean sameID (PeerID pid) - { - boolean equal = true; - for (int i = 0; equal && i < id.length; i++) { - equal = id[i] == pid.id[i]; - } - return equal; - } - - /** - * Two PeerIDs are equal when they have the same id, address and port. - */ - @Override - public boolean equals (Object o) - { - if (o instanceof PeerID) { - PeerID pid = (PeerID)o; - - return port == pid.port && address.equals(pid.address) - && sameID(pid); - } else { - return false; - } - } - - /** - * Compares port, address and id. - */ - public int compareTo (Object o) - { - PeerID pid = (PeerID)o; - - int result = port - pid.port; - if (result != 0) { - return result; - } - - result = address.hashCode() - pid.address.hashCode(); - if (result != 0) { - return result; - } - - for (byte element : id) { - result = element - element; - if (result != 0) { - return result; - } - } - - return 0; - } - - /** - * Returns the String "id@address:port" where id is the hex encoded id with - * leading zeros removed. - */ - @Override - public String toString () - { - return idencode(id) + "@" + address + ":" + port; - } - - /** - * Encode an id as a hex encoded string and remove leading zeros. - */ - public static String idencode (byte[] bs) - { - boolean leading_zeros = true; - - StringBuffer sb = new StringBuffer(bs.length * 2); - for (byte element : bs) { - int c = element & 0xFF; - if (leading_zeros && c == 0) { - continue; - } else { - leading_zeros = false; - } - - if (c < 16) { - sb.append('0'); - } - sb.append(Integer.toHexString(c)); - } - - return sb.toString(); - } - -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/PeerListener.java b/thirdparty/snark/src/java/org/klomp/snark/PeerListener.java deleted file mode 100644 index afc72f88cfa..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/PeerListener.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * PeerListener - Interface for listening to peer events. Copyright (C) 2003 - * Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.IOException; - -/** - * Listener for Peer events. - */ -public interface PeerListener -{ - /** - * Called when the connection to the peer has started and the handshake was - * successfull. - * - * @param peer - * the Peer that just got connected. - */ - void connected (Peer peer); - - /** - * Called when the connection to the peer was terminated or the connection - * handshake failed. - * - * @param peer - * the Peer that just got disconnected. - */ - void disconnected (Peer peer); - - /** - * Called when a choke message is received. - * - * @param peer - * the Peer that got the message. - * @param choke - * true when the peer got a choke message, false when the peer - * got an unchoke message. - */ - void gotChoke (Peer peer, boolean choke); - - /** - * Called when an interested message is received. - * - * @param peer - * the Peer that got the message. - * @param interest - * true when the peer got a interested message, false when the - * peer got an uninterested message. - */ - void gotInterest (Peer peer, boolean interest); - - /** - * Called when a have piece message is received. If the method returns true - * and the peer has not yet received a interested message or we indicated - * earlier to be not interested then an interested message will be send. - * - * @param peer - * the Peer that got the message. - * @param piece - * the piece number that the per just got. - * - * @return true when it is a piece that we want, false if the piece is - * already known. - */ - boolean gotHave (Peer peer, int piece); - - /** - * Called when a bitmap message is received. If this method returns true a - * interested message will be send back to the peer. - * - * @param peer - * the Peer that got the message. - * @param bitfield - * a BitField containing the pieces that the other side has. - * - * @return true when the BitField contains pieces we want, false if the - * piece is already known. - */ - boolean gotBitField (Peer peer, BitField bitfield); - - /** - * Called when a piece is received from the peer. The piece must be - * requested by Peer.request() first. If this method returns false that - * means the Peer provided a corrupted piece and the connection will be - * closed. - * - * @param peer - * the Peer that got the piece. - * @param piece - * the piece number received. - * @param bs - * the byte array containing the piece. - * - * @return true when the bytes represent the piece, false otherwise. - * @throws IOException - */ - boolean gotPiece (Peer peer, int piece, byte[] bs) throws IOException; - - /** - * Called when the peer wants (part of) a piece from us. Only called when - * the peer is not choked by us (peer.choke(false) was - * called). - * - * @param peer - * the Peer that wants the piece. - * @param piece - * the piece number requested. - * - * @return a byte array containing the piece or null when the piece is not - * available (which is a protocol error). - */ - byte[] gotRequest (Peer peer, int piece) throws IOException; - - /** - * Called when a (partial) piece has been downloaded from the peer. - * - * @param peer - * the Peer from which size bytes where downloaded. - * @param size - * the number of bytes that where downloaded. - */ - void downloaded (Peer peer, int size); - - /** - * Called when a (partial) piece has been uploaded to the peer. - * - * @param peer - * the Peer to which size bytes where uploaded. - * @param size - * the number of bytes that where uploaded. - */ - void uploaded (Peer peer, int size); - - /** - * Called when we are downloading from the peer and need to ask for a new - * piece. Might be called multiple times before gotPiece() is - * called. - * - * @param peer - * the Peer that will be asked to provide the piece. - * @param bitfield - * a BitField containing the pieces that the other side has. - * - * @return one of the pieces from the bitfield that we want or -1 if we are - * no longer interested in the peer. - */ - int wantPiece (Peer peer, BitField bitfield); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/PeerMonitorTask.java b/thirdparty/snark/src/java/org/klomp/snark/PeerMonitorTask.java deleted file mode 100644 index 839f0101897..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/PeerMonitorTask.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * PeerMonitorTasks - TimerTask that monitors the peers and total up/down speed - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.util.Iterator; -import java.util.TimerTask; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * TimerTask that monitors the peers and total up/download speeds. Works - * together with the main Snark class to report periodical statistics. - */ -public class PeerMonitorTask extends TimerTask -{ - public static final long MONITOR_PERIOD = 10 * 1000; // Ten seconds. - - private static final long KILOPERSECOND = 1024 * (MONITOR_PERIOD / 1000); - - private final PeerCoordinator coordinator; - - private long lastDownloaded = 0; - - private long lastUploaded = 0; - - public PeerMonitorTask (PeerCoordinator coordinator) - { - this.coordinator = coordinator; - } - - @Override - public void run () - { - // Get some statistics - int peers = 0; - int uploaders = 0; - int downloaders = 0; - int interested = 0; - int interesting = 0; - int choking = 0; - int choked = 0; - - synchronized (coordinator.peers) { - Iterator it = coordinator.peers.iterator(); - while (it.hasNext()) { - Peer peer = (Peer)it.next(); - - // Don't list dying peers - if (!peer.isConnected()) { - continue; - } - - peers++; - - if (!peer.isChoking()) { - uploaders++; - } - if (!peer.isChoked() && peer.isInteresting()) { - downloaders++; - } - if (peer.isInterested()) { - interested++; - } - if (peer.isInteresting()) { - interesting++; - } - if (peer.isChoking()) { - choking++; - } - if (peer.isChoked()) { - choked++; - } - } - } - - // Print some statistics - long downloaded = coordinator.getDownloaded(); - String totalDown; - if (downloaded >= 10 * 1024 * 1024) { - totalDown = (downloaded / (1024 * 1024)) + "MB"; - } else { - totalDown = (downloaded / 1024) + "KB"; - } - long uploaded = coordinator.getUploaded(); - String totalUp; - if (uploaded >= 10 * 1024 * 1024) { - totalUp = (uploaded / (1024 * 1024)) + "MB"; - } else { - totalUp = (uploaded / 1024) + "KB"; - } - - int needP = coordinator.storage.needed(); - long needMB = needP * coordinator.metainfo.getPieceLength(0) - / (1024 * 1024); - int totalP = coordinator.metainfo.getPieces(); - long totalMB = coordinator.metainfo.getTotalLength() / (1024 * 1024); - - log.log(Level.INFO, "Down: " + (downloaded - lastDownloaded) - / KILOPERSECOND + "KB/s" + " (" + totalDown + ")" + " Up: " - + (uploaded - lastUploaded) / KILOPERSECOND + "KB/s" + " (" - + totalUp + ")" + " Need " + needP + " (" + needMB + "MB)" + " of " - + totalP + " (" + totalMB + "MB)" + " pieces"); - log.log(Level.INFO, peers + ": Download #" + downloaders + " Upload #" - + uploaders + " Interested #" + interested + " Interesting #" - + interesting + " Choking #" + choking + " Choked #" + choked); - lastDownloaded = downloaded; - lastUploaded = uploaded; - } - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.status"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/PeerState.java b/thirdparty/snark/src/java/org/klomp/snark/PeerState.java deleted file mode 100644 index e29266e5871..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/PeerState.java +++ /dev/null @@ -1,481 +0,0 @@ -/* - * PeerState - Keeps track of the Peer state through connection callbacks. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -class PeerState -{ - final Peer peer; - - final PeerListener listener; - - final MetaInfo metainfo; - - // Interesting and choking describes whether we are interested in or - // are choking the other side. - boolean interesting = false; - - boolean choking = true; - - // Interested and choked describes whether the other side is - // interested in us or choked us. - boolean interested = false; - - boolean choked = true; - - // Package local for use by Peer. - long downloaded; - - long uploaded; - - BitField bitfield; - - // Package local for use by Peer. - final PeerConnectionIn in; - - final PeerConnectionOut out; - - // Outstanding request - private final List outstandingRequests = new ArrayList(); - - private Request lastRequest = null; - - // If we have te resend outstanding requests (true after we got choked). - private boolean resend = false; - - private final static int MAX_PIPELINE = 5; - - private final static int PARTSIZE = 16384; // 16K - - PeerState (Peer peer, PeerListener listener, MetaInfo metainfo, - PeerConnectionIn in, PeerConnectionOut out) - { - this.peer = peer; - this.listener = listener; - this.metainfo = metainfo; - - this.in = in; - this.out = out; - } - - // NOTE Methods that inspect or change the state synchronize (on this). - - void keepAliveMessage () - { - log.log(Level.FINEST, peer + " rcv alive"); - /* XXX - ignored */ - } - - void chokeMessage (boolean choke) - { - log.log(Level.FINEST, peer + " rcv " + (choke ? "" : "un") + "choked"); - - choked = choke; - if (choked) { - resend = true; - } - - listener.gotChoke(peer, choke); - - if (!choked && interesting) { - request(); - } - } - - void interestedMessage (boolean interest) - { - log.log(Level.FINEST, peer + " rcv " + (interest ? "" : "un") - + "interested"); - interested = interest; - listener.gotInterest(peer, interest); - } - - void haveMessage (int piece) - { - log.log(Level.FINEST, peer + " rcv have(" + piece + ")"); - // Sanity check - if (piece < 0 || piece >= metainfo.getPieces()) { - // XXX disconnect? - log.log(Level.FINER, "Got strange 'have: " + piece - + "' message from " + peer); - return; - } - - synchronized (this) { - // Can happen if the other side never send a bitfield message. - if (bitfield == null) { - bitfield = new BitField(metainfo.getPieces()); - } - - bitfield.set(piece); - } - - if (listener.gotHave(peer, piece)) { - setInteresting(true); - } - } - - void bitfieldMessage (byte[] bitmap) - { - synchronized (this) { - log.log(Level.FINEST, peer + " rcv bitfield"); - if (bitfield != null) { - // XXX - Be liberal in what you accept? - log.log(Level.FINER, "Got unexpected bitfield message from " - + peer); - return; - } - - // XXX - Check for weird bitfield and disconnect? - bitfield = new BitField(bitmap, metainfo.getPieces()); - } - setInteresting(listener.gotBitField(peer, bitfield)); - } - - void requestMessage (int piece, int begin, int length) - throws IOException - { - log.log(Level.FINEST, peer + " rcv request(" + piece + ", " + begin - + ", " + length + ") "); - if (choking) { - log.log(Level.FINER, "Request received, but choking " + peer); - return; - } - - // Sanity check - if (piece < 0 || piece >= metainfo.getPieces() || begin < 0 - || begin > metainfo.getPieceLength(piece) || length <= 0 - || length > 4 * PARTSIZE) { - // XXX - Protocol error -> disconnect? - log.log(Level.FINER, "Got strange 'request: " + piece + ", " - + begin + ", " + length + "' message from " + peer); - return; - } - - byte[] pieceBytes = listener.gotRequest(peer, piece); - if (pieceBytes == null) { - // XXX - Protocol error-> diconnect? - log.log(Level.FINER, "Got request for unknown piece: " + piece); - return; - } - - // More sanity checks - if (begin >= pieceBytes.length || begin + length > pieceBytes.length) { - // XXX - Protocol error-> disconnect? - log.log(Level.FINER, "Got out of range 'request: " + piece + ", " - + begin + ", " + length + "' message from " + peer); - return; - } - - log.log(Level.FINEST, "Sending (" + piece + ", " + begin + ", " - + length + ")" + " to " + peer); - out.sendPiece(piece, begin, length, pieceBytes); - - // Tell about last subpiece delivery. - if (begin + length == pieceBytes.length) { - log.log(Level.FINEST, "Send p" + piece + " " + peer); - } - } - - /** - * Called when some bytes have left the outgoing connection. XXX - Should - * indicate whether it was a real piece or overhead. - */ - void uploaded (int size) - { - uploaded += size; - listener.uploaded(peer, size); - } - - /** - * Called when a partial piece request has been handled by PeerConnectionIn. - */ - void pieceMessage (Request req) - throws IOException - { - int size = req.len; - downloaded += size; - listener.downloaded(peer, size); - - // Last chunk needed for this piece? - if (getFirstOutstandingRequest(req.piece) == -1) { - if (listener.gotPiece(peer, req.piece, req.bs)) { - log.log(Level.FINEST, "Got " + req.piece + ": " + peer); - } else { - log.log(Level.FINEST, "Got BAD " + req.piece + " from " + peer); - // XXX ARGH What now !?! - downloaded = 0; - } - } - } - - synchronized private int getFirstOutstandingRequest (int piece) - { - for (int i = 0; i < outstandingRequests.size(); i++) { - if ((outstandingRequests.get(i)).piece == piece) { - return i; - } - } - return -1; - } - - /** - * Called when a piece message is being processed by the incoming - * connection. Returns null when there was no such request. It also - * requeues/sends requests when it thinks that they must have been lost. - */ - Request getOutstandingRequest (int piece, int begin, int length) - { - log.log(Level.FINEST, "getChunk(" + piece + "," + begin + "," + length - + ") " + peer); - - int r = getFirstOutstandingRequest(piece); - - // Unrequested piece number? - if (r == -1) { - log.log(Level.FINER, "Unrequested 'piece: " + piece + ", " + begin - + ", " + length + "' received from " + peer); - downloaded = 0; // XXX - punishment? - return null; - } - - // Lookup the correct piece chunk request from the list. - Request req; - synchronized (this) { - req = outstandingRequests.get(r); - while (req.piece == piece && req.off != begin - && r < outstandingRequests.size() - 1) { - r++; - req = outstandingRequests.get(r); - } - - // Something wrong? - if (req.piece != piece || req.off != begin || req.len != length) { - log.log(Level.FINER, "Unrequested or unneeded 'piece: " + piece - + ", " + begin + ", " + length + "' received from " + peer); - downloaded = 0; // XXX - punishment? - return null; - } - - // Report missing requests. - if (r != 0) { - String errmsg = "Some requests dropped, got " + req + - ", wanted:"; - for (int i = 0; i < r; i++) { - Request dropReq = outstandingRequests.remove(0); - outstandingRequests.add(dropReq); - // We used to rerequest the missing chunks but that mostly - // just confuses the other side. So now we just keep - // waiting for them. They will be rerequested when we get - // choked/unchoked again. - /* - * if (!choked) out.sendRequest(dropReq); - */ - errmsg += " " + dropReq; - } - errmsg += " " + peer; - log.log(Level.FINER, errmsg); - } - outstandingRequests.remove(0); - } - - // Request more if necessary to keep the pipeline filled. - addRequest(); - - return req; - - } - - void cancelMessage (int piece, int begin, int length) - { - log.log(Level.FINEST, "Got cancel message (" + piece + ", " + begin - + ", " + length + ")"); - out.cancelRequest(piece, begin, length); - } - - void unknownMessage (int type, byte[] bs) - { - log.log(Level.WARNING, "Ignoring unknown message type: " + type - + " length: " + bs.length); - } - - void havePiece (int piece) - { - log.log(Level.FINEST, "Tell " + peer + " havePiece(" + piece + ")"); - - synchronized (this) { - // Tell the other side that we are no longer interested in any of - // the outstanding requests for this piece. - if (lastRequest != null && lastRequest.piece == piece) { - lastRequest = null; - } - - Iterator it = outstandingRequests.iterator(); - while (it.hasNext()) { - Request req = (Request)it.next(); - if (req.piece == piece) { - it.remove(); - // Send cancel even when we are choked to make sure that it - // is - // really never ever send. - out.sendCancel(req); - } - } - } - - // Tell the other side that we really have this piece. - out.sendHave(piece); - - // Request something else if necessary. - addRequest(); - - synchronized (this) { - // Is the peer still interesting? - if (lastRequest == null) { - setInteresting(false); - } - } - } - - // Starts or resumes requesting pieces. - private void request () - { - // Are there outstanding requests that have to be resend? - if (resend) { - out.sendRequests(outstandingRequests); - resend = false; - } - - // Add/Send some more requests if necessary. - addRequest(); - } - - /** - * Adds a new request to the outstanding requests list. - */ - private void addRequest () - { - boolean more_pieces = true; - while (more_pieces) { - synchronized (this) { - more_pieces = outstandingRequests.size() < MAX_PIPELINE; - } - - // We want something and we don't have outstanding requests? - if (more_pieces && lastRequest == null) { - more_pieces = requestNextPiece(); - } else if (more_pieces) // We want something - { - int pieceLength; - boolean isLastChunk; - synchronized (this) { - pieceLength = metainfo.getPieceLength(lastRequest.piece); - isLastChunk = lastRequest.off + lastRequest.len == pieceLength; - } - - // Last part of a piece? - if (isLastChunk) { - more_pieces = requestNextPiece(); - } else { - synchronized (this) { - int nextPiece = lastRequest.piece; - int nextBegin = lastRequest.off + PARTSIZE; - byte[] bs = lastRequest.bs; - int maxLength = pieceLength - nextBegin; - int nextLength = maxLength > PARTSIZE ? PARTSIZE - : maxLength; - Request req = new Request(nextPiece, bs, nextBegin, - nextLength); - outstandingRequests.add(req); - if (!choked) { - out.sendRequest(req); - } - lastRequest = req; - } - } - } - } - - log.log(Level.FINEST, peer + " requests " + outstandingRequests); - } - - // Starts requesting first chunk of next piece. Returns true if - // something has been added to the requests, false otherwise. - private boolean requestNextPiece () - { - // Check that we already know what the other side has. - if (bitfield != null) { - int nextPiece = listener.wantPiece(peer, bitfield); - log.log(Level.FINEST, peer + " want piece " + nextPiece); - synchronized (this) { - if (nextPiece != -1 - && (lastRequest == null || lastRequest.piece != nextPiece)) { - int piece_length = metainfo.getPieceLength(nextPiece); - byte[] bs = new byte[piece_length]; - - int length = Math.min(piece_length, PARTSIZE); - Request req = new Request(nextPiece, bs, 0, length); - outstandingRequests.add(req); - if (!choked) { - out.sendRequest(req); - } - lastRequest = req; - return true; - } - } - } - - return false; - } - - synchronized void setInteresting (boolean interest) - { - log.log(Level.FINEST, peer + " setInteresting(" + interest + ")"); - - if (interest != interesting) { - interesting = interest; - out.sendInterest(interest); - - if (interesting && !choked) { - request(); - } - } - } - - synchronized void setChoking (boolean choke) - { - log.log(Level.FINEST, peer + " setChoking(" + choke + ")"); - - if (choking != choke) { - choking = choke; - out.sendChoke(choke); - } - } - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.peer"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/Request.java b/thirdparty/snark/src/java/org/klomp/snark/Request.java deleted file mode 100644 index da3b55a622c..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/Request.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Request - Holds all information needed for a (partial) piece request. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -/** - * Holds all information needed for a partial piece request. - */ -class Request -{ - final int piece; - - final byte[] bs; - - final int off; - - final int len; - - /** - * Creates a new Request. - * - * @param piece - * Piece number requested. - * @param bs - * byte array where response should be stored. - * @param off - * the offset in the array. - * @param len - * the number of bytes requested. - */ - Request (int piece, byte[] bs, int off, int len) - { - this.piece = piece; - this.bs = bs; - this.off = off; - this.len = len; - - // Sanity check - if (piece < 0 || off < 0 || len <= 0 || off + len > bs.length) { - throw new IndexOutOfBoundsException("Illegal Request " + toString()); - } - } - - @Override - public int hashCode () - { - return piece ^ off ^ len; - } - - @Override - public boolean equals (Object o) - { - if (o instanceof Request) { - Request req = (Request)o; - return req.piece == piece && req.off == off && req.len == len; - } - - return false; - } - - @Override - public String toString () - { - return "(" + piece + "," + off + "," + len + ")"; - } -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/ShutdownListener.java b/thirdparty/snark/src/java/org/klomp/snark/ShutdownListener.java deleted file mode 100644 index ca217207220..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/ShutdownListener.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * ShutdownListener - Callback for end of shutdown sequence - * - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -/** - * Callback for end of shutdown sequence. - */ -public interface ShutdownListener -{ - /** - * Called when the SnarkShutdown hook has finished shutting down all - * subcomponents. - */ - void shutdown (); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/Snark.java b/thirdparty/snark/src/java/org/klomp/snark/Snark.java deleted file mode 100644 index c49047452e2..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/Snark.java +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Snark - Main snark program startup class. Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.URL; -import java.net.URLConnection; -import java.net.UnknownHostException; -import java.util.Random; -import java.util.logging.ConsoleHandler; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.klomp.snark.bencode.BDecoder; - -/** - * Main Snark object used to fetch or serve a given file. - * - * @author Mark Wielaard (mark@klomp.org) - */ -public class Snark -{ - /** The lowest port Snark will listen on for connections */ - public final static int MIN_PORT = 6881; - - /** The highest port Snark will listen on for connections */ - public final static int MAX_PORT = 6889; - - /** The path to the file being torrented */ - public String torrent; - - /** The metadata known about the torrent */ - public MetaInfo meta; - - /** The storage helper assisting us */ - public Storage storage; - - /** The coordinator managing our peers */ - public PeerCoordinator coordinator; - - /** Parcels out incoming requests to the appropriate places */ - public ConnectionAcceptor acceptor; - - /** Obtains information on new peers. */ - public TrackerClient trackerclient; - - /** - * Constructs a Snark client. - * @param torrent The address of the torrent to download or file to serve - * @param ip The IP address to use when serving data - * @param user_port The port number to use - * @param slistener A custom {@link StorageListener} to use - * @param clistener A custom {@link CoordinatorListener} to use - */ - public Snark (String torrent, String ip, int user_port, - StorageListener slistener, CoordinatorListener clistener) - { - this.slistener = slistener; - this.clistener = clistener; - this.torrent = torrent; - this.user_port = user_port; - this.ip = ip; - - // Create a new ID and fill it with something random. First nine - // zeros bytes, then three bytes filled with snark and then - // sixteen random bytes. - Random random = new Random(); - int i; - for (i = 0; i < 9; i++) { - id[i] = 0; - } - id[i++] = snark; - id[i++] = snark; - id[i++] = snark; - while (i < 20) { - id[i++] = (byte)random.nextInt(256); - } - - log.log(Level.FINE, "My peer id: " + PeerID.idencode(id)); - } - - /** - * Sets the global logging level of Snark. - */ - public static void setLogLevel (Level level) - { - log.setLevel(level); - log.setUseParentHandlers(false); - Handler handler = new ConsoleHandler(); - handler.setLevel(level); - log.addHandler(handler); - } - - /** - * Returns a human-readable state of Snark. - */ - public String getStateString () - { - return activities[activity]; - } - - /** - * Returns the integer code for the human-readable state of Snark. - */ - public int getState () - { - return activity; - } - - /** - * Establishes basic information such as {@link #id}, opens ports, - * and determines whether to act as a peer or seed. - */ - public void setupNetwork () - throws IOException - { - activity = NETWORK_SETUP; - - IOException lastException = null; - if (user_port != -1) { - port = user_port; - try { - serversocket = new ServerSocket(port); - } catch (IOException ioe) { - lastException = ioe; - } - } else { - for (port = MIN_PORT; serversocket == null && port <= MAX_PORT; port++) { - try { - serversocket = new ServerSocket(port); - } catch (IOException ioe) { - lastException = ioe; - } - } - } - if (serversocket == null) { - String message = "Cannot accept incoming connections "; - if (user_port == -1) { - message = message + "tried ports " + MIN_PORT + " - " - + MAX_PORT; - } else { - message = message + "on port " + user_port; - } - - if (ip != null || user_port != -1) { - abort(message, lastException); - } else { - log.log(Level.WARNING, message); - } - port = -1; - } else { - port = serversocket.getLocalPort(); - log.log(Level.FINE, "Listening on port: " + port); - } - - // Figure out what the torrent argument represents. - meta = null; - File f = null; - try { - InputStream in; - f = new File(torrent); - if (f.exists()) { - in = new FileInputStream(f); - } else { - activity = GETTING_TORRENT; - URL u = new URL(torrent); - URLConnection c = u.openConnection(); - c.connect(); - in = c.getInputStream(); - - if (c instanceof HttpURLConnection) { - // Check whether the page exists - int code = ((HttpURLConnection)c).getResponseCode(); - if (code / 100 != 2) { - // responses - abort("Loading page '" + torrent + "' gave error code " - + code + ", it probably doesn't exists"); - } - } - } - meta = new MetaInfo(new BDecoder(in)); - } catch (IOException ioe) { - // OK, so it wasn't a torrent metainfo file. - if (f != null && f.exists()) { - if (ip == null) { - abort("'" + torrent + "' exists," - + " but is not a valid torrent metainfo file." - + System.getProperty("line.separator") - + " (use --share to create a torrent from it" - + " and start sharing)", ioe); - } else { - // Try to create a new metainfo file - log.log(Level.INFO, - "Trying to create metainfo torrent for '" + torrent - + "'"); - try { - activity = CREATING_TORRENT; - storage = new Storage(f, "http://" + ip + ":" + port - + "/announce", slistener); - storage.create(); - meta = storage.getMetaInfo(); - } catch (IOException ioe2) { - abort("Could not create torrent for '" + torrent + "'", - ioe2); - } - } - } else { - abort("Cannot open '" + torrent + "'", ioe); - } - } - - log.log(Level.INFO, meta.toString()); - } - - /** - * Start the upload/download process and begins exchanging pieces - * with other peers. - */ - public void collectPieces () - throws IOException - { - // When the metainfo torrent was created from an existing file/dir - // it already exists. - if (storage == null) { - try { - activity = CHECKING_STORAGE; - storage = new Storage(meta, slistener); - storage.check(); - } catch (IOException ioe) { - abort("Could not create storage", ioe); - } - } - - activity = COLLECTING_PIECES; - coordinator = new PeerCoordinator(id, meta, storage, clistener); - HttpAcceptor httpacceptor; - if (ip != null) { - MetaInfo m = meta.reannounce("http://" + ip + ":" + port - + "/announce"); - Tracker tracker = new Tracker(m); - try { - tracker.addPeer(meta.getHexInfoHash(), - new PeerID(id, InetAddress.getByName(ip), port)); - } catch (UnknownHostException oops) { - abort("Could not start tracker for " + ip, oops); - } - httpacceptor = new HttpAcceptor(tracker); - // Debug code for writing out .torrent to disk - /* - byte[] torrentData = tracker.getMetaInfo( - meta.getHexInfoHash()).getTorrentData(); - try { - log.log(Level.INFO, "Writing torrent to file " + torrent - + ".torrent"); - FileOutputStream fos = new FileOutputStream(torrent - + ".torrent"); - fos.write(torrentData); - fos.close(); - } catch (IOException e) { - log.log(Level.WARNING, "Could not save torrent file."); - } - */ - } else { - httpacceptor = null; - } - - PeerAcceptor peeracceptor = new PeerAcceptor(coordinator); - acceptor = new ConnectionAcceptor(serversocket, httpacceptor, - peeracceptor); - acceptor.start(); - - if (ip != null) { - log.log(Level.INFO, "Torrent available on " + "http://" + ip + ":" - + port + "/" + meta.getHexInfoHash() + ".torrent"); - } - - trackerclient = new TrackerClient(meta, coordinator, port); - trackerclient.start(); - coordinator.setTracker(trackerclient); - } - - /** - * Aborts program abnormally. - */ - public static void abort (String s) - throws IOException - { - abort(s, null); - } - - /** - * Aborts program abnormally. - */ - public static void abort (String s, IOException ioe) - throws IOException - { - log.log(Level.SEVERE, s, ioe); - throw new IOException(s); - } - - /** The listen port requested by the user */ - protected int user_port; - - /** The port number Snark listens on */ - protected int port; - - /** The IP address to listen on, if applicable */ - protected String ip; - - /** The {@link StorageListener} to send updates to */ - protected StorageListener slistener; - - /** The {@link CoordinatorListener} to send updates to */ - protected CoordinatorListener clistener; - - /** Our BitTorrent client id number, randomly assigned */ - protected byte[] id = new byte[20]; - - /** The server socket that we are using to listen for connections */ - protected ServerSocket serversocket; - - /** - * A magic constant used to identify the Snark library in the clientid. - * - *
Taking Three as the subject to reason about--
-     * A convenient number to state--
-     * We add Seven, and Ten, and then multiply out
-     * By One Thousand diminished by Eight.
-     *
-     * The result we proceed to divide, as you see,
-     * By Nine Hundred and Ninety Two:
-     * Then subtract Seventeen, and the answer must be
-     * Exactly and perfectly true.
- */ - protected static final byte snark = - (((3 + 7 + 10) * (1000 - 8)) / 992) - 17; - - /** An integer indicating Snark's current activity. */ - protected int activity = NOT_STARTED; - - /** The list of possible activities */ - protected static final String[] activities = - {"Not started", "Network setup", "Getting torrent", "Creating torrent", - "Checking storage", "Collecting pieces", "Seeding"}; - - public static final int NOT_STARTED = 0; - public static final int NETWORK_SETUP = 1; - public static final int GETTING_TORRENT = 2; - public static final int CREATING_TORRENT = 3; - public static final int CHECKING_STORAGE = 4; - public static final int COLLECTING_PIECES = 5; - public static final int SEEDING = 6; - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/SnarkShutdown.java b/thirdparty/snark/src/java/org/klomp/snark/SnarkShutdown.java deleted file mode 100644 index 270c8b36d74..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/SnarkShutdown.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * TrackerShutdown - Makes sure everything ends correctly when shutting down. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Makes sure everything ends correctly when shutting down. - */ -public class SnarkShutdown extends Thread -{ - private final Snark snark; - - private final ShutdownListener listener; - - public SnarkShutdown (Snark snark, ShutdownListener listener) - { - this.snark = snark; - this.listener = listener; - } - - @Override - public void run () - { - log.log(Level.INFO, "Shutting down..."); - - log.log(Level.FINE, "Halting ConnectionAcceptor..."); - if (snark.acceptor != null) { - snark.acceptor.halt(); - } - - log.log(Level.FINE, "Halting TrackerClient..."); - if (snark.trackerclient != null) { - snark.trackerclient.halt(); - } - - log.log(Level.FINE, "Halting PeerCoordinator..."); - if (snark.coordinator != null) { - snark.coordinator.halt(); - } - - log.log(Level.FINE, "Closing Storage..."); - if (snark.storage != null) { - try { - snark.storage.close(); - } catch (IOException ioe) { - log.log(Level.SEVERE, "Couldn't properly close storage", ioe); - } - } - - // XXX - Should actually wait till done... - try { - log.log(Level.FINE, "Waiting 5 seconds..."); - Thread.sleep(5 * 1000); - } catch (InterruptedException ie) { /* ignored */ - } - - listener.shutdown(); - } - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.server"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/StaticSnark.java b/thirdparty/snark/src/java/org/klomp/snark/StaticSnark.java deleted file mode 100644 index 39248dc6e19..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/StaticSnark.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * StaticSnark - Main snark startup class for staticly linking with gcj. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.security.Provider; -import java.security.Security; - -import org.klomp.snark.cmd.SnarkApplication; - -/** - * Main snark startup class for staticly linking with gcj. It references somee - * necessary classes that are normally loaded through reflection. - * - * @author Mark Wielaard (mark@klomp.org) - */ -public class StaticSnark -{ - public static void main (String[] args) - { - try { - // The GNU security provider is needed for SHA-1 MessageDigest - // checking. So make sure it is available as a security provider. - Provider gnu = (Provider)Class.forName( - "gnu.java.security.provider.Gnu").newInstance(); - Security.addProvider(gnu); - } catch (Exception e) { - System.err.println("Unable to load GNU security provider"); - System.exit(-1); - } - - // And finally call the normal starting point. - SnarkApplication.main(args); - } -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/Storage.java b/thirdparty/snark/src/java/org/klomp/snark/Storage.java deleted file mode 100644 index d1699f292cb..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/Storage.java +++ /dev/null @@ -1,519 +0,0 @@ -/* - * Storage - Class used to store and retrieve pieces. Copyright (C) 2003 Mark J. - * Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Maintains pieces on disk. Can be used to store and retrieve pieces. - */ -public class Storage -{ - private MetaInfo metainfo; - - private long[] lengths; - - private RandomAccessFile[] rafs; - - private String[] names; - - private final StorageListener listener; - - private final BitField bitfield; - - private int needed; - - // XXX - Not always set correctly - int piece_size; - - int pieces; - - /** The default piece size. */ - private static int MIN_PIECE_SIZE = 256 * 1024; - - /** The maximum number of pieces in a torrent. */ - private static long MAX_PIECES = 100 * 1024 / 20; - - /** - * Creates a new storage based on the supplied MetaInfo. This will try to - * create and/or check all needed files in the MetaInfo. - * - * @exception IOException - * when creating and/or checking files fails. - */ - public Storage (MetaInfo metainfo, StorageListener listener) - throws IOException - { - this.metainfo = metainfo; - this.listener = listener; - needed = metainfo.getPieces(); - bitfield = new BitField(needed); - } - - /** - * Creates a storage from the existing file or directory together with an - * appropriate MetaInfo file as can be announced on the given announce - * String location. - */ - public Storage (File baseFile, String announce, StorageListener listener) - throws IOException - { - this.listener = listener; - - // Create names, rafs and lengths arrays. - getFiles(baseFile); - - long total = 0; - ArrayList lengthsList = new ArrayList(); - for (long length : lengths) { - total += length; - lengthsList.add(length); - } - - piece_size = MIN_PIECE_SIZE; - pieces = (int)((total - 1) / piece_size) + 1; - while (pieces > MAX_PIECES) { - piece_size = piece_size * 2; - pieces = (int)((total - 1) / piece_size) + 1; - } - - // Note that piece_hashes and the bitfield will be filled after - // the MetaInfo is created. - byte[] piece_hashes = new byte[20 * pieces]; - bitfield = new BitField(pieces); - needed = 0; - - List> files = new ArrayList>(); - for (String element : names) { - List file = new ArrayList(); - StringTokenizer st = new StringTokenizer(element, File.separator); - while (st.hasMoreTokens()) { - String part = st.nextToken(); - file.add(part); - } - files.add(file); - } - - if (files.size() == 1) { - files = null; - lengthsList = null; - } - - // Note that the piece_hashes are not correctly setup yet. - metainfo = new MetaInfo(announce, baseFile.getName(), files, - lengthsList, piece_size, piece_hashes, total); - - } - - // Creates piece hases for a new storage. - public void create () throws IOException - { - // Calculate piece_hashes - MessageDigest digest = null; - try { - digest = MessageDigest.getInstance("SHA"); - } catch (NoSuchAlgorithmException nsa) { - throw new InternalError(nsa.toString()); - } - - byte[] piece_hashes = metainfo.getPieceHashes(); - - byte[] piece = new byte[piece_size]; - for (int i = 0; i < pieces; i++) { - int length = getUncheckedPiece(i, piece, 0); - digest.update(piece, 0, length); - byte[] hash = digest.digest(); - for (int j = 0; j < 20; j++) { - piece_hashes[20 * i + j] = hash[j]; - } - - bitfield.set(i); - - if (listener != null) { - listener.storageChecked(this, i, true); - } - } - - if (listener != null) { - listener.storageAllChecked(this); - } - - // Reannounce to force recalculating the info_hash. - metainfo = metainfo.reannounce(metainfo.getAnnounce()); - } - - private void getFiles (File base) throws IOException - { - ArrayList files = new ArrayList(); - addFiles(files, base); - - int size = files.size(); - names = new String[size]; - lengths = new long[size]; - rafs = new RandomAccessFile[size]; - - int i = 0; - Iterator it = files.iterator(); - while (it.hasNext()) { - File f = (File)it.next(); - names[i] = f.getPath(); - lengths[i] = f.length(); - rafs[i] = new RandomAccessFile(f, "r"); - i++; - } - } - - private static void addFiles (List l, File f) - { - if (!f.isDirectory()) { - l.add(f); - } else { - File[] files = f.listFiles(); - if (files == null) { - log.log(Level.WARNING, "Skipping '" + f - + "' not a normal file."); - return; - } - for (File element : files) { - addFiles(l, element); - } - } - } - - /** - * Returns the MetaInfo associated with this Storage. - */ - public MetaInfo getMetaInfo () - { - return metainfo; - } - - /** - * How many pieces are still missing from this storage. - */ - public int needed () - { - return needed; - } - - /** - * Whether or not this storage contains all pieces if the MetaInfo. - */ - public boolean complete () - { - return needed == 0; - } - - /** - * The BitField that tells which pieces this storage contains. Do not change - * this since this is the current state of the storage. - */ - public BitField getBitField () - { - return bitfield; - } - - /** - * Creates (and/or checks) all files from the metainfo file list. - */ - public void check () throws IOException - { - File base = new File(filterName(metainfo.getName())); - - List files = metainfo.getFiles(); - if (files == null) { - // Create base as file. - log.log(Level.INFO, "Creating/Checking file: " + base); - if (!base.createNewFile() && !base.exists()) { - throw new IOException("Could not create file " + base); - } - - lengths = new long[1]; - rafs = new RandomAccessFile[1]; - names = new String[1]; - lengths[0] = metainfo.getTotalLength(); - rafs[0] = new RandomAccessFile(base, "rw"); - names[0] = base.getName(); - } else { - // Create base as dir. - log.log(Level.INFO, "Creating/Checking directory: " + base); - if (!base.mkdir() && !base.isDirectory()) { - throw new IOException("Could not create directory " + base); - } - - List ls = metainfo.getLengths(); - int size = files.size(); - long total = 0; - lengths = new long[size]; - rafs = new RandomAccessFile[size]; - names = new String[size]; - for (int i = 0; i < size; i++) { - File f = createFileFromNames(base, (List)files.get(i)); - lengths[i] = ((Long)ls.get(i)).longValue(); - total += lengths[i]; - rafs[i] = new RandomAccessFile(f, "rw"); - names[i] = f.getName(); - } - - // Sanity check for metainfo file. - long metalength = metainfo.getTotalLength(); - if (total != metalength) { - throw new IOException("File lengths do not add up " + total - + " != " + metalength); - } - } - checkCreateFiles(); - } - - /** - * Removes 'suspicious' characters from the give file name. - */ - private String filterName (String name) - { - // XXX - Is this enough? - return name.replace(File.separatorChar, '_'); - } - - private File createFileFromNames (File base, List names) throws IOException - { - File f = null; - Iterator it = names.iterator(); - while (it.hasNext()) { - String name = filterName((String)it.next()); - if (it.hasNext()) { - // Another dir in the hierarchy. - f = new File(base, name); - if (!f.mkdir() && !f.isDirectory()) { - throw new IOException("Could not create directory " + f); - } - base = f; - } else { - // The final element (file) in the hierarchy. - f = new File(base, name); - if (!f.createNewFile() && !f.exists()) { - throw new IOException("Could not create file " + f); - } - } - } - return f; - } - - private void checkCreateFiles () throws IOException - { - // Whether we are resuming or not, - // if any of the files already exists we assume we are resuming. - boolean resume = false; - - // Make sure all files are available and of correct length - for (int i = 0; i < rafs.length; i++) { - long length = rafs[i].length(); - if (length == lengths[i]) { - if (listener != null) { - listener.storageAllocated(this, length); - } - resume = true; // XXX Could dynamicly check - } else if (length == 0) { - allocateFile(i); - } else { - log.log(Level.FINE, "Truncating '" + names[i] - + "' from " + lengths + " to " + lengths[i] + "bytes"); - rafs[i].setLength(lengths[i]); - allocateFile(i); - } - } - - // Check which pieces match and which don't - if (resume) { - pieces = metainfo.getPieces(); - byte[] piece = new byte[metainfo.getPieceLength(0)]; - for (int i = 0; i < pieces; i++) { - int length = getUncheckedPiece(i, piece, 0); - boolean correctHash = metainfo.checkPiece(i, piece, 0, length); - if (correctHash) { - bitfield.set(i); - needed--; - } - - if (listener != null) { - listener.storageChecked(this, i, correctHash); - } - } - } - - if (listener != null) { - listener.storageAllChecked(this); - } - } - - private void allocateFile (int nr) throws IOException - { - // XXX - Is this the best way to make sure we have enough space for - // the whole file? - listener.storageCreateFile(this, names[nr], lengths[nr]); - final int ZEROBLOCKSIZE = metainfo.getPieceLength(0); - byte[] zeros = new byte[ZEROBLOCKSIZE]; - int i; - for (i = 0; i < lengths[nr] / ZEROBLOCKSIZE; i++) { - rafs[nr].write(zeros); - if (listener != null) { - listener.storageAllocated(this, ZEROBLOCKSIZE); - } - } - int size = (int)(lengths[nr] - i * ZEROBLOCKSIZE); - rafs[nr].write(zeros, 0, size); - if (listener != null) { - listener.storageAllocated(this, size); - } - } - - /** - * Closes the Storage and makes sure that all RandomAccessFiles are closed. - * The Storage is unusable after this. - */ - public void close () throws IOException - { - for (RandomAccessFile element : rafs) { - synchronized (element) { - element.close(); - } - } - } - - /** - * Returns a byte array containing the requested piece or null if the - * storage doesn't contain the piece yet. - */ - public byte[] getPiece (int piece) throws IOException - { - if (!bitfield.get(piece)) { - return null; - } - - byte[] bs = new byte[metainfo.getPieceLength(piece)]; - getUncheckedPiece(piece, bs, 0); - return bs; - } - - /** - * Put the piece in the Storage if it is correct. - * - * @return true if the piece was correct (sha metainfo hash matches), - * otherwise false. - * @exception IOException - * when some storage related error occurs. - */ - public boolean putPiece (int piece, byte[] bs) throws IOException - { - // First check if the piece is correct. - // If we were paranoia we could copy the array first. - int length = bs.length; - boolean correctHash = metainfo.checkPiece(piece, bs, 0, length); - if (listener != null) { - listener.storageChecked(this, piece, correctHash); - } - if (!correctHash) { - return false; - } - - synchronized (bitfield) { - if (bitfield.get(piece)) { - return true; // No need to store twice. - } else { - bitfield.set(piece); - needed--; - } - } - - long start = piece * metainfo.getPieceLength(0); - int i = 0; - long raflen = lengths[i]; - while (start > raflen) { - i++; - start -= raflen; - raflen = lengths[i]; - } - - int written = 0; - int off = 0; - while (written < length) { - int need = length - written; - int len = (start + need < raflen) ? need : (int)(raflen - start); - synchronized (rafs[i]) { - rafs[i].seek(start); - rafs[i].write(bs, off + written, len); - } - written += len; - if (need - len > 0) { - i++; - raflen = lengths[i]; - start = 0; - } - } - - return true; - } - - private int getUncheckedPiece (int piece, byte[] bs, int off) - throws IOException - { - // XXX - copy/paste code from putPiece(). - long start = piece * metainfo.getPieceLength(0); - int length = metainfo.getPieceLength(piece); - int i = 0; - long raflen = lengths[i]; - while (start > raflen) { - i++; - start -= raflen; - raflen = lengths[i]; - } - - int read = 0; - while (read < length) { - int need = length - read; - int len = (start + need < raflen) ? need : (int)(raflen - start); - synchronized (rafs[i]) { - rafs[i].seek(start); - rafs[i].readFully(bs, off + read, len); - } - read += len; - if (need - len > 0) { - i++; - raflen = lengths[i]; - start = 0; - } - } - - return length; - } - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.Storage"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/StorageListener.java b/thirdparty/snark/src/java/org/klomp/snark/StorageListener.java deleted file mode 100644 index 48eb3341008..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/StorageListener.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * StorageListener.java - Interface used as callback when storage changes. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -/** - * Callback used when Storage changes. - */ -public interface StorageListener -{ - /** - * Called when the storage creates a new file of a given length. - */ - void storageCreateFile (Storage storage, String name, long length); - - /** - * Called to indicate that length bytes have been allocated. - */ - void storageAllocated (Storage storage, long length); - - /** - * Called when storage is being checked and the num piece of that total - * pieces has been checked. When the piece hash matches the expected piece - * hash checked will be true, otherwise it will be false. - */ - void storageChecked (Storage storage, int num, boolean checked); - - /** - * Called when all pieces in the storage have been checked. Does not mean - * that the storage is complete, just that the state of the storage is - * known. - */ - void storageAllChecked (Storage storage); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/Tracker.java b/thirdparty/snark/src/java/org/klomp/snark/Tracker.java deleted file mode 100644 index fb678985f77..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/Tracker.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Tracker - Keeps track of clients sharing a particular torrent MetaInfo. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.ByteArrayOutputStream; -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.klomp.snark.bencode.BEncoder; - -/** - * Keeps track of clients sharing a particular torrent MetaInfo. - */ -public class Tracker -{ - private static final int INTERVAL_SEC = 15 * 60; // 15 minutes. - - private final Map metainfo = - new HashMap(); - - private final Set info_hashes = new HashSet(); - - private Map> peers = - new HashMap>(); - - public Tracker (HashSet hashes) - { - for (String hash : hashes) { - info_hashes.add(hash); - peers.put(hash, new HashSet()); - } - } - - public Tracker (MetaInfo info) - { - String hash = info.getHexInfoHash(); - info_hashes.add(hash); - metainfo.put(hash, info); - peers.put(hash, new HashSet()); - } - - public MetaInfo getMetaInfo (String hash) - { - return metainfo.get(hash); - } - - public void addPeer (String info_hash, PeerID peer) - { - HashSet peerset = peers.get(info_hash); - if (peerset != null) { - synchronized (peerset) { - peerset.add(peer); - } - } - } - - public byte[] handleRequest (InetAddress address, int port, Map params) - { - log.log(Level.FINE, "TrackerReq " + address + ":" + port + " -> " - + params); - - String info_hash_value = (String)params.get("info_hash"); - if (info_hash_value == null) { - return failure("No info_hash given"); - } - info_hash_value = info_hash_value.replace("%", ""); - - boolean found = false; - for (String hash : info_hashes) { - if (hash.equals(info_hash_value)) { - found = true; - } - } - if (!found) { - return failure("Tracker doesn't handle given info_hash"); - } - - byte[] peer_id; - String peer_id_value = (String)params.get("peer_id"); - if (peer_id_value == null) { - return failure("No peer_id given"); - } - - peer_id = urldecode(peer_id_value); - if (peer_id.length != 20) { - return failure("peer_id must be 20 bytes long"); - } - - int peer_port; - String peer_port_value = (String)params.get("port"); - if (peer_port_value == null) { - return failure("No port given"); - } - - try { - peer_port = Integer.parseInt(peer_port_value); - } catch (NumberFormatException nfe) { - return failure("port not a number: " + nfe); - } - - // This is unsafe although other trackers support it. - // It is nice for people that use proxies, but opens up - // a whole can of worms (filling the tracker with fake ips). - // - // It could bee allowed for private use and local addresses - // See RFC1918 and 127.0.0.0/8. - /* - * String ip = (String)params.get("ip"); if (ip != null) { try { address = - * InetAddress.getByName(ip); } catch (UnknownHostException uhe) { } } - */ - - PeerID peer = new PeerID(peer_id, address, peer_port); - - Map response = new HashMap(); - Set peerset = peers.get(info_hash_value); - synchronized (peerset) { - String event = (String)params.get("event"); - if ("stopped".equals(event)) { - peerset.remove(peer); - } else { - peerset.add(peer); - } - - response.put("interval", new Integer(INTERVAL_SEC)); - List> peerList = new ArrayList>(); - Iterator it = peerset.iterator(); - while (it.hasNext()) { - PeerID peerID = (PeerID)it.next(); - Map m = new HashMap(); - m.put("peer id", peerID.getID()); - m.put("ip", peerID.getAddress().getHostAddress()); - m.put("port", new Integer(peerID.getPort())); - peerList.add(m); - } - response.put("peers", peerList); - } - - log.log(Level.FINE, "Tracker response: " + response); - - return BEncoder.bencode(response); - } - - private static byte[] failure (String s) - { - Map m = new HashMap(); - m.put("failure reason", s); - return BEncoder.bencode(m); - } - - /** - * Cheap (but slow) urldecode String to byte array. - */ - static byte[] urldecode (String s) - { - s = s.replace('+', ' '); - char[] cs = s.toCharArray(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - int i = 0; - while (i < cs.length) { - if (cs[i] != '%') { - baos.write((byte)cs[i]); - i++; - } else if (i + 2 < cs.length) { - int val = 16 * Character.digit(cs[i + 1], 16) - + Character.digit(cs[i + 2], 16); - baos.write((byte)val); - i += 3; - } else { - i++; - } - } - return baos.toByteArray(); - } - - protected static final Logger log = Logger.getLogger("org.klomp.snark.Tracker"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/TrackerClient.java b/thirdparty/snark/src/java/org/klomp/snark/TrackerClient.java deleted file mode 100644 index 93822ffea31..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/TrackerClient.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * TrackerClient - Class that informs a tracker and gets new peers. Copyright - * (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.util.Iterator; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Informs metainfo tracker of events and gets new peers for peer coordinator. - * - * @author Mark Wielaard (mark@klomp.org) - */ -public class TrackerClient extends Thread -{ - private static final String NO_EVENT = ""; - - private static final String STARTED_EVENT = "started"; - - private static final String COMPLETED_EVENT = "completed"; - - private static final String STOPPED_EVENT = "stopped"; - - private final static int SLEEP = 1; // Check in with tracker every minute - - private final MetaInfo meta; - - private final PeerCoordinator coordinator; - - private final int port; - - private boolean stop; - - private long interval; - - private long lastRequestTime; - - public TrackerClient (MetaInfo meta, PeerCoordinator coordinator, int port) - { - // Set unique name. - super("TrackerClient-" + urlencode(coordinator.getID())); - this.meta = meta; - this.coordinator = coordinator; - - // XXX - No way to actaully give the tracker feedback that we - // don't run a peer acceptor on any port so use discard 9/tcp sink null - this.port = (port == -1) ? 9 : port; - - stop = false; - } - - /** - * Interrupts this Thread to stop it. - */ - public void halt () - { - stop = true; - this.interrupt(); - } - - @Override - public void run () - { - // XXX - Support other IPs - String announce = meta.getAnnounce(); - String infoHash = urlencode(meta.getInfoHash()); - String peerID = urlencode(coordinator.getID()); - - long uploaded = coordinator.getUploaded(); - long downloaded = coordinator.getDownloaded(); - long left = coordinator.getLeft(); - - boolean completed = coordinator.completed(); - - boolean started = false; - try { - int failures = 0; - while (!started && failures < MAX_FAILURE_COUNT) { - try { - // Send start. - TrackerInfo info = doRequest(announce, infoHash, peerID, - uploaded, downloaded, left, STARTED_EVENT); - Iterator it = info.getPeers().iterator(); - while (it.hasNext()) { - coordinator.addPeer((Peer)it.next()); - } - started = true; - } catch (IOException ioe) { - // Probably not fatal (if it doesn't last to long...) - log.log(Level.WARNING, "Could not contact tracker at '" - + announce, ioe); - } - - if (!started) { - failures++; - log.log(Level.FINER, " Retrying in 5s..."); - try { - // Sleep five seconds... - Thread.sleep(5 * 1000); - } catch (InterruptedException interrupt) { - // ignore - } - } - } - - if (failures >= MAX_FAILURE_COUNT) { - throw new IOException("Could not establish initial connection"); - } - - while (!stop) { - try { - // Sleep some minutes... - Thread.sleep(SLEEP * 60 * 1000); - } catch (InterruptedException interrupt) { - // ignore - } - - if (stop) { - break; - } - - uploaded = coordinator.getUploaded(); - downloaded = coordinator.getDownloaded(); - left = coordinator.getLeft(); - - // First time we got a complete download? - String event; - if (!completed && coordinator.completed()) { - completed = true; - event = COMPLETED_EVENT; - } else { - event = NO_EVENT; - } - - // Only do a request when necessary. - if (event == COMPLETED_EVENT || coordinator.needPeers() - || System.currentTimeMillis() > lastRequestTime + interval) { - try { - TrackerInfo info = doRequest(announce, infoHash, - peerID, uploaded, downloaded, left, event); - - Iterator it = info.getPeers().iterator(); - while (it.hasNext()) { - coordinator.addPeer((Peer)it.next()); - } - } catch (IOException ioe) { - // Probably not fatal (if it doesn't last to long...) - log.log(Level.WARNING, "Could not contact tracker at '" - + announce, ioe); - } - } - } - - } catch (Throwable t) { - log.log(Level.SEVERE, "Fatal exception in TrackerClient", t); - } finally { - try { - if (started) { - doRequest(announce, infoHash, peerID, uploaded, downloaded, - left, STOPPED_EVENT); - } - } catch (IOException ioe) { /* ignored */ - } - } - - } - - private TrackerInfo doRequest (String announce, String infoHash, - String peerID, long uploaded, long downloaded, long left, String event) - throws IOException - { - String s = announce + "?info_hash=" + infoHash + "&peer_id=" + peerID - + "&port=" + port + "&uploaded=" + uploaded + "&downloaded=" - + downloaded + "&left=" + left - + ((event != NO_EVENT) ? ("&event=" + event) : ""); - URL u = new URL(s); - log.log(Level.FINE, "Sending TrackerClient request: " + u); - - URLConnection c = u.openConnection(); - c.connect(); - InputStream in = c.getInputStream(); - - if (c instanceof HttpURLConnection) { - // Check whether the page exists - int code = ((HttpURLConnection)c).getResponseCode(); - if (code == HttpURLConnection.HTTP_FORBIDDEN) { - throw new IOException("Tracker doesn't handle given info_hash"); - } else if (code / 100 != 2) { - throw new IOException("Loading '" + s + "' gave error code " - + code + ", it probably doesn't exist"); - } - } - - TrackerInfo info = new TrackerInfo(in, coordinator.getID(), - coordinator.getMetaInfo()); - log.log(Level.FINE, "TrackerClient response: " + info); - lastRequestTime = System.currentTimeMillis(); - - String failure = info.getFailureReason(); - if (failure != null) { - throw new IOException(failure); - } - - interval = info.getInterval() * 1000; - return info; - } - - /** - * Very lazy byte[] to URL encoder. Just encodes everything, even "normal" - * chars. - */ - static String urlencode (byte[] bs) - { - StringBuffer sb = new StringBuffer(bs.length * 3); - for (byte element : bs) { - int c = element & 0xFF; - sb.append('%'); - if (c < 16) { - sb.append('0'); - } - sb.append(Integer.toHexString(c)); - } - - return sb.toString(); - } - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.TrackerClient"); - - /** - * The maximum number of times that we are allowed to fail to make an - * initial contact with the tracker before we bail - */ - protected static final int MAX_FAILURE_COUNT = 2; -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/TrackerInfo.java b/thirdparty/snark/src/java/org/klomp/snark/TrackerInfo.java deleted file mode 100644 index 297b8abe6c7..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/TrackerInfo.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * TrackerInfo - Holds information returned by a tracker, mainly the peer list. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark; - -import java.io.IOException; -import java.io.InputStream; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.klomp.snark.bencode.BDecoder; -import org.klomp.snark.bencode.BEValue; -import org.klomp.snark.bencode.InvalidBEncodingException; - -public class TrackerInfo -{ - private final String failure_reason; - - private final int interval; - - private final Set peers; - - public TrackerInfo (InputStream in, byte[] my_id, MetaInfo metainfo) - throws IOException - { - this(new BDecoder(in), my_id, metainfo); - } - - public TrackerInfo (BDecoder be, byte[] my_id, MetaInfo metainfo) - throws IOException - { - this(be.bdecodeMap().getMap(), my_id, metainfo); - } - - public TrackerInfo (Map m, byte[] my_id, MetaInfo metainfo) - throws IOException - { - BEValue reason = (BEValue)m.get("failure reason"); - if (reason != null) { - failure_reason = reason.getString(); - interval = -1; - peers = null; - } else { - failure_reason = null; - BEValue beInterval = (BEValue)m.get("interval"); - if (beInterval == null) { - throw new InvalidBEncodingException("No interval given"); - } else { - interval = beInterval.getInt(); - } - BEValue bePeers = (BEValue)m.get("peers"); - if (bePeers == null) { - throw new InvalidBEncodingException("No peer list"); - } else { - peers = getPeers(bePeers.getList(), my_id, metainfo); - } - } - } - - public static Set getPeers (InputStream in, byte[] my_id, MetaInfo metainfo) - throws IOException - { - return getPeers(new BDecoder(in), my_id, metainfo); - } - - public static Set getPeers (BDecoder be, byte[] my_id, MetaInfo metainfo) - throws IOException - { - return getPeers(be.bdecodeList().getList(), my_id, metainfo); - } - - public static Set getPeers (List l, byte[] my_id, MetaInfo metainfo) - throws IOException - { - Set peers = new HashSet(l.size()); - - Iterator it = l.iterator(); - while (it.hasNext()) { - PeerID peerID = new PeerID(((BEValue)it.next()).getMap()); - peers.add(new Peer(peerID, my_id, metainfo)); - } - - return peers; - } - - public Set getPeers () - { - return peers; - } - - public String getFailureReason () - { - return failure_reason; - } - - public int getInterval () - { - return interval; - } - - @Override - public String toString () - { - if (failure_reason != null) { - return "TrackerInfo[FAILED: " + failure_reason + "]"; - } else { - return "TrackerInfo[interval=" + interval + ", peers=" + peers - + "]"; - } - } -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/bencode/BDecoder.java b/thirdparty/snark/src/java/org/klomp/snark/bencode/BDecoder.java deleted file mode 100644 index 5be5c72fcbb..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/bencode/BDecoder.java +++ /dev/null @@ -1,358 +0,0 @@ -/* - * BDecoder - Converts an InputStream to BEValues. Copyright (C) 2003 Mark J. - * Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark.bencode; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Decodes a bencoded stream to BEValues. - * - * A bencoded byte stream can represent byte arrays, numbers, lists and maps - * (dictionaries). - * - * It currently contains a hack to indicate a name of a dictionary of which a - * SHA-1 digest hash should be calculated (the hash over the original bencoded - * bytes). - * - * @author Mark Wielaard (mark@klomp.org). - */ -public class BDecoder -{ - // The InputStream to BDecode. - private final InputStream in; - - // The last indicator read. - // Zero if unknown. - // '0'..'9' indicates a byte[]. - // 'i' indicates an Number. - // 'l' indicates a List. - // 'd' indicates a Map. - // 'e' indicates end of Number, List or Map (only used internally). - // -1 indicates end of stream. - // Call getNextIndicator to get the current value (will never return zero). - private int indicator = 0; - - // Used for ugly hack to get SHA hash over the metainfo info map - private String special_map = "info"; - - private boolean in_special_map = false; - - private final MessageDigest sha_digest; - - // Ugly hack. Return the SHA has over bytes that make up the special map. - public byte[] get_special_map_digest () - { - byte[] result = sha_digest.digest(); - return result; - } - - // Ugly hack. Name defaults to "info". - public void set_special_map_name (String name) - { - special_map = name; - } - - /** - * Initalizes a new BDecoder. Nothing is read from the given - * InputStream yet. - */ - public BDecoder (InputStream in) - { - this.in = in; - // XXX - Used for ugly hack. - try { - sha_digest = MessageDigest.getInstance("SHA"); - } catch (NoSuchAlgorithmException nsa) { - throw new InternalError(nsa.toString()); - } - } - - /** - * Creates a new BDecoder and immediatly decodes the first value it sees. - * - * @return The first BEValue on the stream or null when the stream has - * ended. - * - * @exception InvalidBEncoding - * when the stream doesn't start with a bencoded value or the - * stream isn't a bencoded stream at all. - * @exception IOException - * when somthing bad happens with the stream to read from. - */ - public static BEValue bdecode (InputStream in) throws IOException - { - return new BDecoder(in).bdecode(); - } - - /** - * Returns what the next bencoded object will be on the stream or -1 when - * the end of stream has been reached. Can return something unexpected (not - * '0' .. '9', 'i', 'l' or 'd') when the stream isn't bencoded. - * - * This might or might not read one extra byte from the stream. - */ - public int getNextIndicator () throws IOException - { - if (indicator == 0) { - indicator = in.read(); - // XXX - Used for ugly hack - if (in_special_map) { - sha_digest.update((byte)indicator); - } - } - return indicator; - } - - /** - * Gets the next indicator and returns either null when the stream has ended - * or bdecodes the rest of the stream and returns the appropriate BEValue - * encoded object. - */ - public BEValue bdecode () throws IOException - { - indicator = getNextIndicator(); - if (indicator == -1) { - return null; - } - - if (indicator >= '0' && indicator <= '9') { - return bdecodeBytes(); - } else if (indicator == 'i') { - return bdecodeNumber(); - } else if (indicator == 'l') { - return bdecodeList(); - } else if (indicator == 'd') { - return bdecodeMap(); - } else { - throw new InvalidBEncodingException("Unknown indicator '" - + indicator + "'"); - } - } - - /** - * Returns the next bencoded value on the stream and makes sure it is a byte - * array. If it is not a bencoded byte array it will throw - * InvalidBEncodingException. - */ - public BEValue bdecodeBytes () throws IOException - { - int c = getNextIndicator(); - int num = c - '0'; - if (num < 0 || num > 9) { - throw new InvalidBEncodingException("Number expected, not '" - + (char)c + "'"); - } - indicator = 0; - - c = read(); - int i = c - '0'; - while (i >= 0 && i <= 9) { - // XXX - This can overflow! - num = num * 10 + i; - c = read(); - i = c - '0'; - } - - if (c != ':') { - throw new InvalidBEncodingException("Colon expected, not '" - + (char)c + "'"); - } - - return new BEValue(read(num)); - } - - /** - * Returns the next bencoded value on the stream and makes sure it is a - * number. If it is not a number it will throw InvalidBEncodingException. - */ - public BEValue bdecodeNumber () throws IOException - { - int c = getNextIndicator(); - if (c != 'i') { - throw new InvalidBEncodingException("Expected 'i', not '" + (char)c - + "'"); - } - indicator = 0; - - c = read(); - if (c == '0') { - c = read(); - if (c == 'e') { - return new BEValue(BigInteger.ZERO); - } else { - throw new InvalidBEncodingException("'e' expected after zero," - + " not '" + (char)c + "'"); - } - } - - // XXX - We don't support more the 255 char big integers - char[] chars = new char[256]; - int off = 0; - - if (c == '-') { - c = read(); - if (c == '0') { - throw new InvalidBEncodingException("Negative zero not allowed"); - } - chars[off] = (char)c; - off++; - } - - if (c < '1' || c > '9') { - throw new InvalidBEncodingException("Invalid Integer start '" - + (char)c + "'"); - } - chars[off] = (char)c; - off++; - - c = read(); - int i = c - '0'; - while (i >= 0 && i <= 9) { - chars[off] = (char)c; - off++; - c = read(); - i = c - '0'; - } - - if (c != 'e') { - throw new InvalidBEncodingException("Integer should end with 'e'"); - } - - String s = new String(chars, 0, off); - return new BEValue(new BigInteger(s)); - } - - /** - * Returns the next bencoded value on the stream and makes sure it is a - * list. If it is not a list it will throw InvalidBEncodingException. - */ - public BEValue bdecodeList () throws IOException - { - int c = getNextIndicator(); - if (c != 'l') { - throw new InvalidBEncodingException("Expected 'l', not '" + (char)c - + "'"); - } - indicator = 0; - - List result = new ArrayList(); - c = getNextIndicator(); - while (c != 'e') { - result.add(bdecode()); - c = getNextIndicator(); - } - indicator = 0; - - return new BEValue(result); - } - - /** - * Returns the next bencoded value on the stream and makes sure it is a map - * (dictonary). If it is not a map it will throw InvalidBEncodingException. - */ - public BEValue bdecodeMap () throws IOException - { - int c = getNextIndicator(); - if (c != 'd') { - throw new InvalidBEncodingException("Expected 'd', not '" + (char)c - + "'"); - } - indicator = 0; - - Map result = new HashMap(); - c = getNextIndicator(); - while (c != 'e') { - // Dictonary keys are always strings. - String key = bdecode().getString(); - - // XXX ugly hack - boolean special = special_map.equals(key); - if (special) { - in_special_map = true; - } - - BEValue value = bdecode(); - result.put(key, value); - - // XXX ugly hack continued - if (special) { - in_special_map = false; - } - - c = getNextIndicator(); - } - indicator = 0; - - return new BEValue(result); - } - - /** - * Returns the next byte read from the InputStream (as int). Throws - * EOFException if InputStream.read() returned -1. - */ - private int read () throws IOException - { - int c = in.read(); - if (c == -1) { - throw new EOFException(); - } - if (in_special_map) { - sha_digest.update((byte)c); - } - return c; - } - - /** - * Returns a byte[] containing length valid bytes starting at offset zero. - * Throws EOFException if InputStream.read() returned -1 before all - * requested bytes could be read. Note that the byte[] returned might be - * bigger then requested but will only contain length valid bytes. The - * returned byte[] will be reused when this method is called again. - */ - private byte[] read (int length) throws IOException - { - byte[] result = new byte[length]; - - int read = 0; - while (read < length) { - int i = in.read(result, read, length - read); - if (i == -1) { - throw new EOFException(); - } - read += i; - } - - if (in_special_map) { - sha_digest.update(result, 0, length); - } - return result; - } - -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/bencode/BEValue.java b/thirdparty/snark/src/java/org/klomp/snark/bencode/BEValue.java deleted file mode 100644 index b6952394fa0..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/bencode/BEValue.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * BEValue - Holds different types that a bencoded byte array can represent. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark.bencode; - -import java.io.UnsupportedEncodingException; -import java.util.List; -import java.util.Map; - -/** - * Holds different types that a bencoded byte array can represent. You need to - * call the correct get method to get the correct java type object. If the - * BEValue wasn't actually of the requested type you will get a - * InvalidBEncodingException. - * - * @author Mark Wielaard (mark@klomp.org) - */ -public class BEValue -{ - // This is either a byte[], Number, List or Map. - private final Object value; - - public BEValue (byte[] value) - { - this.value = value; - } - - public BEValue (Number value) - { - this.value = value; - } - - public BEValue (List value) - { - this.value = value; - } - - public BEValue (Map value) - { - this.value = value; - } - - /** - * Returns this BEValue as a String. This operation only succeeds when the - * BEValue is a byte[], otherwise it will throw a InvalidBEncodingException. - * The byte[] will be interpreted as UTF-8 encoded characters. - */ - public String getString () throws InvalidBEncodingException - { - try { - return new String(getBytes(), "UTF-8"); - } catch (ClassCastException cce) { - throw new InvalidBEncodingException(cce.toString()); - } catch (UnsupportedEncodingException uee) { - throw new InternalError(uee.toString()); - } - } - - /** - * Returns this BEValue as a byte[]. This operation only succeeds when the - * BEValue is actually a byte[], otherwise it will throw a - * InvalidBEncodingException. - */ - public byte[] getBytes () throws InvalidBEncodingException - { - try { - return (byte[])value; - } catch (ClassCastException cce) { - throw new InvalidBEncodingException(cce.toString()); - } - } - - /** - * Returns this BEValue as a Number. This operation only succeeds when the - * BEValue is actually a Number, otherwise it will throw a - * InvalidBEncodingException. - */ - public Number getNumber () throws InvalidBEncodingException - { - try { - return (Number)value; - } catch (ClassCastException cce) { - throw new InvalidBEncodingException(cce.toString()); - } - } - - /** - * Returns this BEValue as int. This operation only succeeds when the - * BEValue is actually a Number, otherwise it will throw a - * InvalidBEncodingException. The returned int is the result of - * Number.intValue(). - */ - public int getInt () throws InvalidBEncodingException - { - return getNumber().intValue(); - } - - /** - * Returns this BEValue as long. This operation only succeeds when the - * BEValue is actually a Number, otherwise it will throw a - * InvalidBEncodingException. The returned long is the result of - * Number.longValue(). - */ - public long getLong () throws InvalidBEncodingException - { - return getNumber().longValue(); - } - - /** - * Returns this BEValue as a List of BEValues. This operation only succeeds - * when the BEValue is actually a List, otherwise it will throw a - * InvalidBEncodingException. - */ - public List getList () throws InvalidBEncodingException - { - try { - return (List)value; - } catch (ClassCastException cce) { - throw new InvalidBEncodingException(cce.toString()); - } - } - - /** - * Returns this BEValue as a Map of BEValue keys and BEValue values. This - * operation only succeeds when the BEValue is actually a Map, otherwise it - * will throw a InvalidBEncodingException. - */ - public Map getMap () throws InvalidBEncodingException - { - try { - return (Map)value; - } catch (ClassCastException cce) { - throw new InvalidBEncodingException(cce.toString()); - } - } - - @Override - public String toString () - { - String valueString; - if (value instanceof byte[]) { - byte[] bs = (byte[])value; - // XXX - Stupid heuristic... - if (bs.length <= 12) { - valueString = new String(bs); - } else { - valueString = "bytes:" + bs.length; - } - } else { - valueString = value.toString(); - } - - return "BEValue[" + valueString + "]"; - } -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/bencode/BEncoder.java b/thirdparty/snark/src/java/org/klomp/snark/bencode/BEncoder.java deleted file mode 100644 index 7dd79ac2297..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/bencode/BEncoder.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * BDecoder - Converts an InputStream to BEValues. Copyright (C) 2003 Mark J. - * Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark.bencode; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class BEncoder -{ - - public static byte[] bencode (Object o) throws IllegalArgumentException - { - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - bencode(o, baos); - return baos.toByteArray(); - } catch (IOException ioe) { - throw new InternalError(ioe.toString()); - } - } - - public static void bencode (Object o, OutputStream out) throws IOException, - IllegalArgumentException - { - if (o instanceof String) { - bencode((String)o, out); - } else if (o instanceof byte[]) { - bencode((byte[])o, out); - } else if (o instanceof Number) { - bencode((Number)o, out); - } else if (o instanceof List) { - bencode((List)o, out); - } else if (o instanceof Map) { - bencode((Map)o, out); - } else { - throw new IllegalArgumentException("Cannot bencode: " - + o.getClass()); - } - } - - public static byte[] bencode (String s) - { - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - bencode(s, baos); - return baos.toByteArray(); - } catch (IOException ioe) { - throw new InternalError(ioe.toString()); - } - } - - public static void bencode (String s, OutputStream out) throws IOException - { - byte[] bs = s.getBytes("UTF-8"); - bencode(bs, out); - } - - public static byte[] bencode (Number n) - { - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - bencode(n, baos); - return baos.toByteArray(); - } catch (IOException ioe) { - throw new InternalError(ioe.toString()); - } - } - - public static void bencode (Number n, OutputStream out) throws IOException - { - out.write('i'); - String s = n.toString(); - out.write(s.getBytes("UTF-8")); - out.write('e'); - } - - public static byte[] bencode (List l) - { - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - bencode(l, baos); - return baos.toByteArray(); - } catch (IOException ioe) { - throw new InternalError(ioe.toString()); - } - } - - public static void bencode (List l, OutputStream out) throws IOException - { - out.write('l'); - Iterator it = l.iterator(); - while (it.hasNext()) { - bencode(it.next(), out); - } - out.write('e'); - } - - public static byte[] bencode (byte[] bs) - { - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - bencode(bs, baos); - return baos.toByteArray(); - } catch (IOException ioe) { - throw new InternalError(ioe.toString()); - } - } - - public static void bencode (byte[] bs, OutputStream out) throws IOException - { - String l = Integer.toString(bs.length); - out.write(l.getBytes("UTF-8")); - out.write(':'); - out.write(bs); - } - - public static byte[] bencode (Map m) - { - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - bencode(m, baos); - return baos.toByteArray(); - } catch (IOException ioe) { - throw new InternalError(ioe.toString()); - } - } - - public static void bencode (Map m, OutputStream out) - throws IOException - { - out.write('d'); - - // Keys must be sorted. XXX - But is this the correct order? - Set s = m.keySet(); - List l = new ArrayList(s); - Collections.sort(l); - - for (String key : l) { - Object value = m.get(key); - bencode(key, out); - bencode(value, out); - } - - out.write('e'); - } -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/bencode/InvalidBEncodingException.java b/thirdparty/snark/src/java/org/klomp/snark/bencode/InvalidBEncodingException.java deleted file mode 100644 index 9682d56a3c0..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/bencode/InvalidBEncodingException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * InvalidBEncodingException - Thrown when a bencoded stream is corrupted. - * Copyright (C) 2003 Mark J. Wielaard - * - * This file is part of Snark. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.klomp.snark.bencode; - -import java.io.IOException; - -/** - * Exception thrown when a bencoded stream is corrupted. - * - * @author Mark Wielaard (mark@klomp.org) - */ -public class InvalidBEncodingException extends IOException -{ - public InvalidBEncodingException (String message) - { - super(message); - } -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/cmd/ConsoleStorageReporter.java b/thirdparty/snark/src/java/org/klomp/snark/cmd/ConsoleStorageReporter.java deleted file mode 100644 index 42511b064e2..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/cmd/ConsoleStorageReporter.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.klomp.snark.cmd; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.klomp.snark.MetaInfo; -import org.klomp.snark.Storage; -import org.klomp.snark.StorageListener; - -/** - * Reports the status of allocation of space via logging data to - * the console. - * - * @author Elizabeth Fong (elizabeth@ctyalcove.org) - */ -public class ConsoleStorageReporter implements StorageListener -{ - public void storageCreateFile (Storage storage, String name, long length) - { - log.log(Level.FINE, "Creating file '" + name + "' of length " + - length + ": "); - } - - // How much storage space has been allocated - private long allocated = 0; - - public void storageAllocated (Storage storage, long length) - { - System.err.print("."); - allocated += length; - if (allocated == storage.getMetaInfo().getTotalLength()) { - System.err.println(); - log.log(Level.INFO, "Finished allocating storage space"); - } - } - - boolean allChecked = false; - - boolean checking = false; - - public void storageChecked (Storage storage, int num, boolean checked) - { - if (!allChecked && !checking) { - // Use the MetaInfo from the storage since our own might not - // yet be setup correctly. - MetaInfo meta = storage.getMetaInfo(); - if (meta != null) { - log.log(Level.INFO, "Checking existing " + meta.getPieces() - + " pieces: "); - } - checking = true; - } - if (checking) { - if (checked) { - System.err.print("+"); - } else { - System.err.print("-"); - } - } else { - log.log(Level.FINE, "Got " + (checked ? "" : "BAD ") + "piece: " - + num); - } - } - - public void storageAllChecked (Storage storage) - { - allChecked = true; - checking = false; - } - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.storage"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/cmd/SnarkApplication.java b/thirdparty/snark/src/java/org/klomp/snark/cmd/SnarkApplication.java deleted file mode 100644 index c6fad5f145a..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/cmd/SnarkApplication.java +++ /dev/null @@ -1,293 +0,0 @@ -package org.klomp.snark.cmd; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Logger; -import java.util.logging.Level; -import java.util.Timer; -import java.util.TimerTask; - -import org.klomp.snark.CoordinatorListener; -import org.klomp.snark.Peer; -import org.klomp.snark.PeerMonitorTask; -import org.klomp.snark.ShutdownListener; -import org.klomp.snark.Snark; -import org.klomp.snark.SnarkShutdown; -import org.klomp.snark.StorageListener; - -/** - * A basic command line interface to the Snark library. - * - * @author Elizabeth Fong (elizabeth@threerings.net) - */ -public class SnarkApplication -{ - public static void main (String[] args) - { - System.out.println(copyright); - System.out.println(); - - // Parse debug, share/ip and torrent file options. - Snark snark = parseArguments(args, new ConsoleStorageReporter(), null); - boolean interactive = true; - boolean showPeers = false; - for (String arg : args) { - if (arg.equals("--no-commands")) { - interactive = false; - } - if (arg.equals("--show-peers") || arg.equals("--share")) { - showPeers = true; - } - }; - - // Set things up to exit gracefully - ShutdownListener listener = new ShutdownListener() { - // documentation inherited from interface ShutdownListener - public void shutdown () - { - // Should not be necessary since all non-deamon threads should - // have died. But in reality this does not always happen. - System.exit(0); - } - }; - SnarkShutdown hook = new SnarkShutdown(snark, listener); - Runtime.getRuntime().addShutdownHook(hook); - - // Let's start grabbing files! - try { - snark.setupNetwork(); - snark.collectPieces(); - } catch (IOException ioe) { - System.exit(-1); - } - - // If requested, periodically monitor progress. - if (showPeers) { - Timer timer = new Timer(true); - TimerTask monitor = new PeerMonitorTask(snark.coordinator); - timer.schedule(monitor, PeerMonitorTask.MONITOR_PERIOD, - PeerMonitorTask.MONITOR_PERIOD); - } - - // Start interactive command interpreter if desired - if (interactive) { - doInteractive(snark, hook); - } - } - - /** - * Initializes the user-interactive readline interface to Snark - */ - protected static void doInteractive (Snark snark, SnarkShutdown hook) - { - boolean quit = false; - - System.out.println(); - System.out.println(usage); - System.out.println(); - - try { - BufferedReader br = new BufferedReader(new InputStreamReader( - System.in)); - String line = br.readLine(); - while (!quit && line != null) { - line = line.toLowerCase(); - if ("quit".equals(line)) { - quit = true; - } else if ("list".equals(line)) { - synchronized (snark.coordinator.peers) { - System.out.println(snark.coordinator.peers.size() - + " peers -" + " (i)nterested," + " (I)nteresting," - + " (c)hoking," + " (C)hoked:"); - Iterator it = snark.coordinator.peers.iterator(); - while (it.hasNext()) { - Peer peer = (Peer)it.next(); - System.out.println(peer); - System.out.println("\ti: " + peer.isInterested() - + " I: " + peer.isInteresting() + " c: " - + peer.isChoking() + " C: " + peer.isChoked()); - } - } - } else if ("info".equals(line)) { - System.out.println("Name: " + snark.meta.getName()); - System.out.println("Torrent: " + snark.torrent); - System.out.println("Tracker: " + snark.meta.getAnnounce()); - List files = snark.meta.getFiles(); - System.out.println("Files: " - + ((files == null) ? 1 : files.size())); - System.out.println("Pieces: " + snark.meta.getPieces()); - System.out.println("Piece size: " - + snark.meta.getPieceLength(0) / 1024 + " KB"); - System.out.println("Total size: " - + snark.meta.getTotalLength() / (1024 * 1024) + " MB"); - } else if ("state".equals(line)) { - System.out.println( - snark.storage.getBitField().getHumanReadable()); - System.out.println("Total peers: " - + snark.coordinator.getPeers()); - System.out.println("Total size: " - + snark.meta.getTotalLength() / (1024 * 1024) + " MB"); - System.out.println("Total remaining: " - + snark.coordinator.getLeft() / (1024 * 1024) + " MB"); - System.out.println("Total downloaded: " - + snark.coordinator.getDownloaded()); - System.out.println("Total uploaded: " - + snark.coordinator.getUploaded()); - } else if ("".equals(line) || "help".equals(line)) { - System.out.println(usage); - System.out.println(help); - } else { - System.out.println("Unknown command: " + line); - System.out.println(usage); - } - - if (!quit) { - System.out.println(); - line = br.readLine(); - } - } - } catch (IOException ioe) { - log.log(Level.SEVERE, "Unable to read stdin", ioe); - } - - // Explicit shutdown. - Runtime.getRuntime().removeShutdownHook(hook); - hook.start(); - } - - /** - * Prints messages about proper usage of the Snark application. - */ - protected static void usage (String s) - { - PrintStream stream = System.out; - if (s != null) { - stream = System.err; - stream.println("snark: " + s); - } - stream.println("Usage: snark [--debug [level]] [--no-commands] [--port ]"); - stream.println(" [--show-peers] [--share (|)] (||)"); - stream.println(" --debug\tShows some extra info and stacktraces"); - stream.println(" level\tHow much debug details to show"); - stream.println(" \t(defaults to " + Level.SEVERE - + ", with --debug to " + Level.INFO + ", highest level is " - + Level.ALL + ")."); - stream.println(" --no-commands\tDon't read interactive commands or show usage info."); - stream.println(" --port\tThe port to listen on for incomming connections"); - stream.println(" \t(if not given defaults to first free port between " - + Snark.MIN_PORT + "-" + Snark.MAX_PORT + ")."); - stream.println(" --show-peers\tIf enabled, periodically prints peer information."); - stream.println(" --share\tStart torrent tracker on address or name."); - stream.println(" \tURL pointing to .torrent metainfo file to download/share."); - stream.println(" \tEither a local .torrent metainfo file to download"); - stream.println(" \tor (with --share) a file to share."); - stream.println(" \tA directory with files to share (needs --share)."); - System.exit(-1); - } - - /** - * A convenience method for parsing arguments passed via the command line - * where no overriding of the listeners is required. - */ - public static Snark parseArguments (String[] args) - { - return parseArguments(args, null, null); - } - - /** - * Sets debug, ip and torrent variables then creates a Snark instance. Calls - * usage(), which terminates the program, if non-valid argument list. The - * given listeners will be passed to all components that take one. - */ - public static Snark parseArguments (String[] args, - StorageListener slistener, CoordinatorListener clistener) - { - int user_port = -1; - String ip = null; - String torrent = null; - Level level = Level.INFO; - - int i = 0; - while (i < args.length) { - if (args[i].equals("--debug")) { - level = Level.FINE; - i++; - - // Try if there is an level argument. - if (i < args.length) { - try { - level = Level.parse(args[i]); - } catch (IllegalArgumentException iae) { - // continue parsing arguments - } - i++; - } - } else if (args[i].equals("--port")) { - if (args.length - 1 < i + 1) { - usage("--port needs port number to listen on"); - } - try { - user_port = Integer.parseInt(args[i + 1]); - } catch (NumberFormatException nfe) { - usage("--port argument must be a number (" + nfe + ")"); - } - i += 2; - } else if (args[i].equals("--share")) { - if (args.length - 1 < i + 1) { - usage("--share needs local ip-address or host-name"); - } - ip = args[i + 1]; - i += 2; - } else if (args[i].equals("--no-commands") || - args[i].equals("--show-peers")) { - // ignore, processed elsewhere. - i++; - } else if (args[i].equals("--help")) { - usage(null); - } else { - torrent = args[i]; - i++; - break; - } - } - log.setLevel(level); - Snark.setLogLevel(level); - - if (torrent == null || i != args.length) { - if (torrent != null && torrent.startsWith("-")) { - usage("Unknown option '" + torrent + "'."); - } else { - usage("Need exactly one , or ."); - } - } - - Snark snark = new Snark(torrent, ip, user_port, slistener, clistener); - return snark; - } - - protected static final String newline = System.getProperty("line.separator"); - - protected static final String copyright = - "The Hunting of the Snark Project - " - + "Copyright (C) 2003 Mark J. Wielaard, (c) 2006 Three Rings Design" - + newline - + newline - + "Snark comes with ABSOLUTELY NO WARRANTY. This is free software, and" - + newline - + "you are welcome to redistribute it under certain conditions; read the" - + newline + "COPYING file for details."; - - /** The message displayed when entering the interactive interface */ - protected static final String usage = - "Press return for help. Type \"quit\" and return to stop."; - - /** A list of commands that the interactive interface accepts */ - protected static final String help = "Commands: 'info', 'list', 'quit'."; - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.cmd"); -} diff --git a/thirdparty/snark/src/java/org/klomp/snark/tracker/TrackerApplication.java b/thirdparty/snark/src/java/org/klomp/snark/tracker/TrackerApplication.java deleted file mode 100644 index cf9b2d9d294..00000000000 --- a/thirdparty/snark/src/java/org/klomp/snark/tracker/TrackerApplication.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.klomp.snark.tracker; - -import java.io.IOException; -import java.io.PrintStream; -import java.net.ServerSocket; -import java.util.HashSet; -import java.util.logging.Logger; -import java.util.logging.Level; - -import org.klomp.snark.ConnectionAcceptor; -import org.klomp.snark.HttpAcceptor; -import org.klomp.snark.Snark; -import org.klomp.snark.Tracker; - -/** - * A basic command line interface to the Snark library. - * - * @author Elizabeth Fong (elizabeth@threerings.net) - */ -public class TrackerApplication -{ - public static void main (String[] args) - { - System.out.println(copyright); - System.out.println(); - - // Parse debug, share/ip and torrent file options. - try { - ConnectionAcceptor acceptor = parseArguments(args); - acceptor.start(); - /* - while (true) { - - } - */ - } catch (IOException ioe) { - log.log(Level.SEVERE, "Could not open port", ioe); - } - } - - /** - * Prints messages about proper usage of the Snark application. - */ - protected static void usage (String s) - { - PrintStream stream = System.out; - if (s != null) { - stream = System.err; - stream.println("snark: " + s); - } - stream.println( - "Usage: snark [--debug [level]] [--no-commands] [--port ] [ ...]"); - stream.println(" --debug\tShows some extra info and stacktraces"); - stream.println(" level\tHow much debug details to show"); - stream.println(" \t(defaults to " + Level.SEVERE - + ", with --debug to " + Level.INFO + ", highest level is " - + Level.ALL + ")."); - stream.println(" --port\tThe port to listen on for incomming connections"); - stream.println(" \t(if not given defaults to 6969)"); - stream.println(" \tAn infohash for a torrent file shared using the tracker."); - System.exit(-1); - } - - /** - * Sets debug, ip and torrent variables then creates a Snark instance. Calls - * usage(), which terminates the program, if non-valid argument list. The - * given listeners will be passed to all components that take one. - */ - public static ConnectionAcceptor parseArguments (String[] args) - throws IOException - { - int user_port = DEFAULT_PORT; - Level level = Level.INFO; - HashSet hashes = new HashSet(); - - int i = 0; - while (i < args.length) { - if (args[i].equals("--debug")) { - level = Level.FINE; - i++; - - // Try if there is an level argument. - if (i < args.length) { - try { - level = Level.parse(args[i]); - } catch (IllegalArgumentException iae) { - // continue parsing arguments - } - } - } else if (args[i].equals("--port")) { - if (args.length - 1 < i + 1) { - usage("--port needs port number to listen on"); - } - try { - user_port = Integer.parseInt(args[i + 1]); - } catch (NumberFormatException nfe) { - usage("--port argument must be a number (" + nfe + ")"); - } - i += 2; - } else if (args[i].equals("--help")) { - usage(null); - } else { - hashes.add(args[i]); - i++; - break; - } - } - log.setLevel(level); - Snark.setLogLevel(level); - - if (hashes.isEmpty()) { - usage("Need at least one ."); - } - - Tracker tracker = new Tracker(hashes); - HttpAcceptor httpacceptor = new HttpAcceptor(tracker); - ConnectionAcceptor acceptor = new ConnectionAcceptor( - new ServerSocket(user_port), httpacceptor, null); - return acceptor; - } - - protected static final String newline = System.getProperty("line.separator"); - - protected static final String copyright = - "The Hunting of the Snark Project - " - + "Copyright (C) 2003 Mark J. Wielaard, (c) 2006 Three Rings Design" - + newline - + newline - + "Snark comes with ABSOLUTELY NO WARRANTY. This is free software, and" - + newline - + "you are welcome to redistribute it under certain conditions; read the" - + newline + "COPYING file for details."; - - /** The Java logger used to process our log events. */ - protected static final Logger log = Logger.getLogger("org.klomp.snark.cmd"); - - protected static final int DEFAULT_PORT = 6969; -} diff --git a/thirdparty/virtualdns/ErrorMessages.java b/thirdparty/virtualdns/ErrorMessages.java deleted file mode 100644 index c164aff7386..00000000000 --- a/thirdparty/virtualdns/ErrorMessages.java +++ /dev/null @@ -1,73 +0,0 @@ -/* VirtualDNS - A modular DNS server. - * Copyright (C) 2000 Eric Kidd - * Copyright (C) 1999 Brian Wellington - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -import java.io.*; -import org.xbill.DNS.*; -import org.xbill.DNS.utils.*; - -/************************************************************************* - * Routines for creating different kinds of DNS error responses. - ************************************************************************* - * This code was adapted from Brian Wellington's jnamed code. - * @see org.xbill.DNS.Message - */ - -public class ErrorMessages { - - /********************************************************************* - * Create a format error message (FORMERR). - ********************************************************************* - * @param in The malformed packet. - * @return A DNS error message. - */ - public static Message makeFormatErrorMessage(byte [] in) { - Header header; - try { - header = new Header(in); - } - catch (IOException e) { - header = new Header(0); - } - Message response = new Message(); - response.setHeader(header); - for (int i = 0; i < 4; i++) - response.removeAllRecords(i); - header.setRcode(Rcode.FORMERR); - return response; - } - - /********************************************************************* - * Create an arbitrary DNS error message. - ********************************************************************* - * @param query The query sent by the user. - * @param rcode The response code to use for this error. - * @return A DNS error message. - * @see org.xbill.DNS.Rcode - */ - public static Message makeErrorMessage(SOARecord soa, Message response, short rcode) { - Header header = response.getHeader(); -// Message response = new Message(); -// response.setHeader(header); - for (int i = 1; i < 4; i++) - response.removeAllRecords(i); - response.addRecord(soa, Section.AUTHORITY); - header.setRcode(rcode); - return response; - } -} diff --git a/thirdparty/virtualdns/VirtualDNS.java b/thirdparty/virtualdns/VirtualDNS.java deleted file mode 100644 index 2cc4fdc708b..00000000000 --- a/thirdparty/virtualdns/VirtualDNS.java +++ /dev/null @@ -1,311 +0,0 @@ -import java.io.*; -import java.lang.reflect.Method; -import java.net.*; -import java.util.Iterator; -import org.apache.log4j.Logger; -import org.apache.log4j.PropertyConfigurator; - - -import org.xbill.DNS.*; -/* - * A simple DNS server that maps a-b-c-d.foo.com to a.b.c.d and rejects everything else - */ -public class VirtualDNS { - - static Logger logger = Logger.getLogger(VirtualDNS.class.getName()); - - - String domain; - Zone zone; - - // Timeout values, in milliseconds. These are pretty arbitrary. We're - // just trying to shut down unused connections promptly. - static private final int TCP_TIMEOUT = 60000; - - /********************************************************************* - * Create and run a new DNS server. - ********************************************************************* - * @param port The port on which to run the server. - */ - public VirtualDNS(String domain, String zonefile, short port) throws IOException { - this.domain = domain; - this.zone = new Zone(new Name(domain + "."), zonefile); - // Start our two server processes. - addUDP(port); - addTCP(port); - } - - // Create a new TCP listener process. - private void addTCP(final short port) { - Thread t; - t = new Thread(new Runnable() {public void run() {serveTCP(port);}}); - t.start(); - } - - // Create a new UDP listener process. - private void addUDP(final short port) { - Thread t; - t = new Thread(new Runnable() {public void run() {serveUDP(port);}}); - t.start(); - } - - // Our TCP listener process. - private void serveTCP(short port) { - try { - ServerSocket sock = new ServerSocket(port); - while (true) { - final Socket s = sock.accept(); - Thread t = new Thread(new Runnable() { - public void run () { - processTCP(s); - } - }); - t.start(); - } - } - catch (IOException e) { - logger.error("serveTCP failed: " + e); - } - } - - // Read and respond to a TCP request. - private void processTCP (Socket s) - { - try { - int inLength; - DataInputStream dataIn; - DataOutputStream dataOut; - byte [] in; - - s.setSoTimeout(TCP_TIMEOUT); - - try { - InputStream is = s.getInputStream(); - dataIn = new DataInputStream(is); - inLength = dataIn.readUnsignedShort(); - in = new byte[inLength]; - dataIn.readFully(in); - } - catch (InterruptedIOException e) { - s.close(); - return; - } - Message query, response; - try { - query = new Message(in); - response = generateReply(query, in, s, s.getInetAddress()); - if (response == null) - return; - } - catch (IOException e) { - response = ErrorMessages.makeFormatErrorMessage(in); - } - byte [] out = response.toWire(); - dataOut = new DataOutputStream(s.getOutputStream()); - dataOut.writeShort(out.length); - dataOut.write(out); - - } catch (IOException e) { - logger.error("processTCP: " + e); - } finally { - try { - s.close(); - } catch (IOException e) {} - } - } - - // Our UDP listener process. - private void serveUDP(short port) { - try { - DatagramSocket sock = new DatagramSocket(port); - while (true) { - short udpLength = 512; - DatagramPacket dp = new DatagramPacket(new byte[512], - 512); - try { - sock.receive(dp); - } - catch (InterruptedIOException e) { - continue; - } - byte [] in = new byte[dp.getLength()]; - System.arraycopy(dp.getData(), 0, in, 0, in.length); - Message query, response; - try { - query = new Message(in); - response = generateReply(query, in, null, dp.getAddress()); - if (response == null) - continue; - } - catch (IOException e) { - response = ErrorMessages.makeFormatErrorMessage(in); - } - byte [] out = response.toWire(); - - dp = new DatagramPacket(out, out.length, - dp.getAddress(), dp.getPort()); - sock.send(dp); - } - } - catch (IOException e) { - logger.error("serveUDP: " + e); - } - } - - byte[] getAddr(String hostname) { - byte[] result = new byte[4]; - String[] fields = hostname.split("-", 10); - if (fields.length != 4) { - return null; - } - for (int i = 0; i < 4; i++) { - try { - int n = Integer.parseInt(fields[i]); - if (n > 255) { - return null; - } - result[i] = (byte)n; - } catch (NumberFormatException e) { - return null; - } - } - return result; - } - - void addRRset(Message response, RRset rrset, int section) { - Iterator it = rrset.rrs(); - while(it.hasNext()) { - Record r = (Record)it.next(); - response.addRecord(r, section); - } - } - // Construct a proper reply packet. - private Message generateReply(Message query, byte [] in, Socket s, InetAddress src) { - - // Refuse everything but standard DNS queries. - if (query.getHeader().getOpcode() != Opcode.QUERY) - return ErrorMessages.makeErrorMessage(zone.getSOA(), query, (short)Rcode.NOTIMPL); - - // Get some useful information from the query. - // XXX - What should we do if we get the wrong query version? - Record queryRecord = query.getQuestion(); - OPTRecord queryOPT = query.getOPT(); - Name name = queryRecord.getName(); - short type = (short)queryRecord.getType(); - short dclass = (short)queryRecord.getDClass(); - - logger.info("request id=" + query.getHeader().getID() + " src=" + src + " name=" + name + " type=" + type); - - if (dclass != DClass.IN) { - return ErrorMessages.makeErrorMessage(zone.getSOA(), query, (short)Rcode.NOTIMPL); - } - - // XXX - Is this the right thing to do with TSIGs? - if (query.getTSIG() != null) - return ErrorMessages.makeErrorMessage(zone.getSOA(), query, (short)Rcode.NOTIMPL); - - // Start building our response packet. - Message response = new Message(); - response.getHeader().setID(query.getHeader().getID()); - response.getHeader().setFlag(Flags.QR); - response.getHeader().setFlag(Flags.AA); - response.addRecord(queryRecord, Section.QUESTION); - - // Reject zone transfer requests--our zone is dynamic. - if (type == Type.AXFR && s != null) - return ErrorMessages.makeErrorMessage(zone.getSOA(), response, (short)Rcode.REFUSED); - - // Return an error if we get asked for unsupported record types. - if (!Type.isRR(type) && type != Type.ANY) - return ErrorMessages.makeErrorMessage(zone.getSOA(), response, (short)Rcode.NOTIMPL); - if (type == Type.SIG) - return ErrorMessages.makeErrorMessage(zone.getSOA(), response, (short)Rcode.NOTIMPL); - - logger.trace("Querying zone name=" + name + " type=" + type); - response.getHeader().setFlag(Flags.AA); - - SetResponse staticResponse = zone.findRecords(name, type); - if (staticResponse.isSuccessful()) { - logger.trace("Zone query successful"); - RRset [] rrsets = staticResponse.answers(); - for (int j = 0; j < rrsets.length; j++) { - addRRset(response, rrsets[j], Section.ANSWER); - } - return response; - } - if (staticResponse.isNXRRSET()) { - return ErrorMessages.makeErrorMessage(zone.getSOA(), response, (short)Rcode.NOERROR); - } - -// logger.trace("Zone query failed isNXDOMAIN="+staticResponse.isNXDOMAIN() + " isNXRRSET=" + staticResponse.isNXRRSET()); - - //System.out.println("name = " + name); - - String fullname = name.toString(); - - if (fullname.charAt(fullname.length() - 1) != '.') { - return ErrorMessages.makeErrorMessage(zone.getSOA(), response, (short)Rcode.FORMERR); - } - - fullname = fullname.substring(0, fullname.length() - 1); - int i = fullname.indexOf('.'); - if (i < 0) { - return ErrorMessages.makeErrorMessage(zone.getSOA(), response, (short)Rcode.NXDOMAIN); - } - - String hostname = fullname.substring(0, i); - String domainname = fullname.substring(i+1); - - if (!domainname.equals(domain)) { - return ErrorMessages.makeErrorMessage(zone.getSOA(), response, (short)Rcode.NXDOMAIN); - } - - //System.out.println("hostname = " + hostname); - - byte[] addr = getAddr(hostname); - - if (addr == null) { - return ErrorMessages.makeErrorMessage(zone.getSOA(), response, (short)Rcode.NXDOMAIN); - } - InetAddress iaddr; - try { - iaddr = InetAddress.getByAddress(fullname, addr); - } catch (UnknownHostException e) { - return ErrorMessages.makeErrorMessage(zone.getSOA(), response, (short)Rcode.NXDOMAIN); - } - - if (type != Type.A) { - // DNS servers return NOERROR for entries that exist but have different type of records - return ErrorMessages.makeErrorMessage(zone.getSOA(), response, (short)Rcode.NOERROR); - } - - ARecord record = new ARecord(name, DClass.IN, 24 * 3600, iaddr); - - response.addRecord(record, Section.ANSWER); - RRset nss = zone.getNS(); - addRRset(response, nss, Section.AUTHORITY); - Iterator it = nss.rrs(); - while(it.hasNext()) { - NSRecord r = (NSRecord)it.next(); - RRset a = zone.findExactMatch(r.getTarget(), Type.A); - addRRset(response, a, Section.ADDITIONAL); - } - - return response; - } - - public static void main(String [] args) { - if (args.length != 4) { - System.err.println("Usage: VirtualDNS "); - System.exit(1); - } - try { - PropertyConfigurator.configure(args[3]); - short port = (short)Integer.parseInt(args[2]); - VirtualDNS s = new VirtualDNS(args[0], args[1], port); - } - catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/thirdparty/virtualdns/build.sh b/thirdparty/virtualdns/build.sh deleted file mode 100755 index 959a3f117ea..00000000000 --- a/thirdparty/virtualdns/build.sh +++ /dev/null @@ -1 +0,0 @@ -javac -target 1.5 -g -cp dnsjava-2.0.6.jar:log4j-1.2.15.jar -d classes VirtualDNS.java ErrorMessages.java diff --git a/thirdparty/virtualdns/log4j.properties b/thirdparty/virtualdns/log4j.properties deleted file mode 100644 index 17a2c520ed7..00000000000 --- a/thirdparty/virtualdns/log4j.properties +++ /dev/null @@ -1,18 +0,0 @@ -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=DEBUG, R - -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd MMM HH:mm:ss,SSS} %-5p - %m%n - -log4j.appender.R.layout=org.apache.log4j.PatternLayout -log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd MMM HH:mm:ss,SSS} %-5p - %m%n - -log4j.appender.R=org.apache.log4j.RollingFileAppender -log4j.appender.R.File=/var/log/dns/dns.log - -log4j.appender.R.MaxFileSize=32MB -log4j.appender.R.MaxBackupIndex=1000 diff --git a/thirdparty/virtualdns/named.realhostip.com b/thirdparty/virtualdns/named.realhostip.com deleted file mode 100644 index 638838b3b17..00000000000 --- a/thirdparty/virtualdns/named.realhostip.com +++ /dev/null @@ -1,19 +0,0 @@ -; Zone file for realhostip.com -; -; The full zone file -; -@ IN SOA realhostip.com. admin.realhostip.com. ( - 201006211 ; serial, todays date + todays serial # - 8H ; refresh, seconds - 2H ; retry, seconds - 4W ; expire, seconds - 1D ) ; minimum, seconds - TXT "realhostip.com" - NS ns.realhostip.com. - NS ns2.realhostip.com. - -localhost A 127.0.0.1 - -ns A 184.72.55.159 -ns2 A 184.72.250.40 -test A 1.2.3.4 diff --git a/thirdparty/virtualdns/run.sh b/thirdparty/virtualdns/run.sh deleted file mode 100755 index 63988938a94..00000000000 --- a/thirdparty/virtualdns/run.sh +++ /dev/null @@ -1 +0,0 @@ -java -cp dnsjava-2.0.6.jar:log4j-1.2.15.jar:classes VirtualDNS $1 $2 $3 $4 $5