From a6b9a614ed6baa6945ecf6cc5a3bb984d8e6d3e3 Mon Sep 17 00:00:00 2001 From: hsn <> Date: Tue, 25 Nov 2003 10:17:37 +0000 Subject: [PATCH] added random check, new random generator --- BETA.README | 4 +- ChangeLog | 4 +- TODO | 6 +-- configure.ac | 2 +- include/s_extern.h | 9 +++- server/Makefile.am | 2 +- server/path.c | 1 + server/random.c | 28 +++++++++++ server/server.c | 14 ------ tests/.cvsignore | 1 + tests/Makefile.am | 4 +- tests/cachecheck.c | 2 +- tests/randomcheck.c | 114 ++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 165 insertions(+), 26 deletions(-) create mode 100644 server/random.c create mode 100644 tests/randomcheck.c diff --git a/BETA.README b/BETA.README index 0792647..808d13e 100644 --- a/BETA.README +++ b/BETA.README @@ -2,11 +2,13 @@ This is a BETA release, as such it's not guaranteed to work perfectly any problems let me know, they'll be sorted out in the next Beta release. At the point at which people stop complaining the non-beta release will be let out. +You can get beta version from CVS on sf.net there are tagged fsp-281-bXX. + FSP Development Battle plan: ============================ * for next 2.8 Stable version (will be called 2.8.2) - add FSP Rename command -- add FSP info command +- add FSP Info command - go out this version as soon as possible. 2.8.1b3 and lower are buggy. * for next point Stable version 2.8.3 - add native symbolic link support diff --git a/ChangeLog b/ChangeLog index 52fb996..92b25f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -Version 2.8.1b18 - 24 Nov 24 2003 +Version 2.8.1b18 - 25 Nov 24 2003 This is MINIMUM REQUIRED VERSION for applicatins which are using javafsp library, only download machine atm. javafsp library will be released shortly as separate package. @@ -26,6 +26,8 @@ Version 2.8.1b18 - 24 Nov 24 2003 parsecheck added to 'make check' support for multiple \n in filename - in future there will be used for symlinks. + random generator changed to one recommended by Jiann-Ming Su. + new test program tests/randomcheck.c - tests random number generators. Version 2.8.1b17 -- 17 Nov 2003 Allow filenames with spaces inside diff --git a/TODO b/TODO index 036e0c9..b3faac9 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,12 @@ -FSP SUITE TO DO LIST BY RADIM KOLAR /hsn -at- cybermail * net / +FSP SUITE TO DO LIST BY RADIM KOLAR +/* maintained by hsn -at- cybermail * net */ LARGEFILES64 how to turn them on: Cygwin: #define __LARGE64_FILES fopen64,ftello64,fseeko64 _off64_t glibc 2.3: #define _LARGEFILE64_SOURCE off64_t native: _FILE_OFFSETS_BITS = 32 / 64 then use off_t -Radim Kolar's personal wishlist 1997 +Radim Kolar's personal wishlist from 1997 show loosers online (finfo command) and server statz rename command password change command @@ -26,7 +27,6 @@ PORTING Sven's Slowaris 8 compile problem NEEDS IMPROVMENT: -random number generator in server is low random quality on low bits. Client LIBRARY local bind address FSP_LOCALIP diff --git a/configure.ac b/configure.ac index 79f9ed9..58e1f30 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a working configure script. dnl tested with autoconf 2.57 -AC_INIT(fsp,2.8.1b17+cvs,hsn@cybermail.net) +AC_INIT(fsp,2.8.1b18,hsn@cybermail.net) AC_CONFIG_SRCDIR(server/main.c) AM_INIT_AUTOMAKE([dist-bzip2]) AM_MAINTAINER_MODE diff --git a/include/s_extern.h b/include/s_extern.h index 1219b8f..e57dc7c 100644 --- a/include/s_extern.h +++ b/include/s_extern.h @@ -25,7 +25,6 @@ int init_caches PROTO0((void)); void shutdown_caches PROTO0((void)); void stat_caches PROTO1(FILE *,fp); const char *validate_path PROTO0((char *, unsigned, PPATH *,DIRINFO **, int)); -const char *parse_path PROTO3(char *, fullp, unsigned int, len, PPATH *, pp); const char *server_get_dir PROTO0((DIRLISTING **,const DIRINFO *)); const char *server_del_file PROTO0((PPATH *, DIRINFO *)); const char *server_del_dir PROTO2(PPATH *, pp, DIRINFO *,di); @@ -48,6 +47,12 @@ void init_home_dir PROTO0((void)); /* filecache.c, open filehandles cache */ +/* path.c, path parser */ +const char *parse_path PROTO3(char *, fullp, unsigned int, len, PPATH *, pp); + +/* random.c, next key random degenerator */ +unsigned short gen_next_key PROTO0((void)); + /* iprange.c IP range services */ extern IPrange *iptab; const char *check_ip_table PROTO2(unsigned long, inet_num,IPrange *,table); @@ -77,7 +82,7 @@ const char * require_access_rights PROTO4(const DIRINFO *,di,unsigned char,right /* main.c, startup and init code */ -/* log.c */ +/* log.c, log writter */ extern int logfd; extern int tlogfd; void fsplogf PROTO0((void)); diff --git a/server/Makefile.am b/server/Makefile.am index 89ffe1e..484f5a9 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -3,7 +3,7 @@ bin_PROGRAMS=fspd fspd_SOURCES=file.c host.c main.c conf.c filecache.c server.c fifocache.c \ - log.c iprange.c acl.c path.c + log.c iprange.c acl.c path.c random.c fspd_CFLAGS=-DSYSCONFDIR="\"@sysconfdir@\"" $(AM_CFLAGS) fspd_LDADD=-L../common -lcommon diff --git a/server/path.c b/server/path.c index aa8eef2..c330bff 100644 --- a/server/path.c +++ b/server/path.c @@ -11,6 +11,7 @@ #include "tweak.h" #include "server_def.h" #include "s_extern.h" +#include "my-string.h" /***************************************************************************** * Routine to parse a path string given by the client. diff --git a/server/random.c b/server/random.c new file mode 100644 index 0000000..956b197 --- /dev/null +++ b/server/random.c @@ -0,0 +1,28 @@ +#include "tweak.h" +#include "server_def.h" +#include "s_extern.h" + +/**************************************************************************** + * Routine to return a 16-bit key with random number. + ****************************************************************************/ + + +/* The following algorithm is recommended by Numerical Recipies. */ +/* Best, but needs floating point division. */ +unsigned short gen_next_key PROTO0 ((void)) +{ + unsigned short ulRandom = ((float)(0xffff)*rand()/(RAND_MAX+1.0f)); + return(ulRandom); +} + +#if 0 +unsigned short gen_next_key PROTO0((void)) +{ + unsigned long k; + + k = random(); + k = k ^ (k >> 8) ^ (k >> 16) ^ (k << 8); + + return k; +} +#endif diff --git a/server/server.c b/server/server.c index eb09aa5..a9238a4 100644 --- a/server/server.c +++ b/server/server.c @@ -295,20 +295,6 @@ int server_loop PROTO2(int, fd, time_t, timeout) } } -/**************************************************************************** - * Routine to return a 16-bit key with random number. - ****************************************************************************/ - -static unsigned short gen_next_key PROTO0((void)) -{ - unsigned long k; - - k = random(); - k = k ^ (k >> 8) ^ (k >> 16) ^ (k << 8); - - return(k & 0xffff); -} - /**************************************************************************** * Generic routine for sending reply back to clients. * from: client address structure. diff --git a/tests/.cvsignore b/tests/.cvsignore index c67857c..d41b8c7 100644 --- a/tests/.cvsignore +++ b/tests/.cvsignore @@ -4,3 +4,4 @@ Makefile.in mklargefile cachecheck parsecheck +randomcheck diff --git a/tests/Makefile.am b/tests/Makefile.am index 2bd5f6e..76158ae 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,7 @@ -noinst_PROGRAMS=mklargefile cachecheck parsecheck +noinst_PROGRAMS=mklargefile cachecheck parsecheck randomcheck extra_DIST=mklargefile.py cachecheck_SOURCES=../server/fifocache.c cachecheck.c parsecheck_SOURCES=parsecheck.c ../server/path.c -TESTS=parsecheck +TESTS=parsecheck randomcheck diff --git a/tests/cachecheck.c b/tests/cachecheck.c index aa5eda4..8f86dc9 100644 --- a/tests/cachecheck.c +++ b/tests/cachecheck.c @@ -2,11 +2,11 @@ * made by radim kolar. */ +#include "tweak.h" #include #include #include #include -#include "tweak.h" #include "../server/fifocache.h" static int intcompare(const int *i1,const int *i2) diff --git a/tests/randomcheck.c b/tests/randomcheck.c new file mode 100644 index 0000000..2c27c61 --- /dev/null +++ b/tests/randomcheck.c @@ -0,0 +1,114 @@ +#include "tweak.h" +#include +#include +#include "my-string.h" +#include + +static int bitcount[16]; +static int rounds; +static int result; +#define MAX_WORST_ALLOWED 0.2f + +/* FSP classic algo */ +static unsigned short classic PROTO0((void)) +{ + unsigned long k; + + k = random(); + k = k ^ (k >> 8) ^ (k >> 16) ^ (k << 8); + + return k; +} + +/* get low bits from random result */ +static unsigned short simple PROTO0((void)) +{ + return random(); +} + +/* get high bits from random result - better */ +static unsigned short simple2 PROTO0((void)) +{ + return (random() >> 15); +} + +/* The following algorithm is recommended by Numerical Recipies: */ +/* Best, but needs floating point division */ +static unsigned short nr(void) +{ + unsigned short ulRandom = ((float)(0xffff)*rand()/(RAND_MAX+1.0f)); + return(ulRandom); +} + +static void run_randomtest( unsigned short (*keygen)(void) ) +{ + int i,j; + unsigned short rnd; + + /* zero bitcount first */ + memset(bitcount,0,16*sizeof(int)); + + for(i=0;i>1; + } + } +} + +static void print_bitcount(void) +{ + int i; + float worst; + float ratio; + + printf("Set ratio: "); + worst=0; + + for(i=0;i<16;i++) + { + ratio=(float)bitcount[i]/rounds; + if(fabs(ratio-0.5f)>worst) + worst=fabs(ratio-0.5f); + printf("%.2f ",ratio); + } + printf(" Worst: %.3f\n",worst); + if(worst>MAX_WORST_ALLOWED) result++; +} + + +int main(int argc,const char *argv[]) +{ + rounds=200; + if(argc>1) + { + rounds=atoi(argv[1]); + } + + printf("Running %d rounds.\n\n",rounds); + + result=0; + + printf("Generator: classic\n"); + run_randomtest(classic); + print_bitcount(); + + printf("Generator: simple\n"); + run_randomtest(simple); + print_bitcount(); + + printf("Generator: simple2\n"); + run_randomtest(simple2); + print_bitcount(); + + result=0; + printf("Generator: Numerical Recipes\n"); + run_randomtest(nr); + print_bitcount(); + return result; +}