Browse Source

fix renaming files in windows to rename instead of delete!

The port of rename file was deleting files, which kind of makes
creating a bundle difficult!

I wrote a mini-test suite to test most of the system specific
functions, this can be invoked via command line ../agents/iguana
OStests or via compile time -D IGUANA_OSTESTS
release/v0.1
jl777 8 years ago
parent
commit
82fa535737
  1. 4
      OSlibs/win/mingw.h
  2. 29
      crypto777/OS_nonportable.c
  3. 24
      crypto777/OS_portable.c
  4. 61
      crypto777/OS_portable.h
  5. 2
      crypto777/SaM.c
  6. 123
      crypto777/iguana_OS.c
  7. 2
      crypto777/inet.c
  8. 2
      crypto777/jpeg/jmemsys.h
  9. 2
      iguana/iguana_bundles.c
  10. 2
      iguana/iguana_init.c
  11. 10
      iguana/iguana_peers.c
  12. 24
      iguana/iguana_ramchain.c
  13. 2
      iguana/iguana_recv.c
  14. 4
      iguana/iguana_spendvectors.c
  15. 2
      iguana/iguana_tx.c
  16. 4
      iguana/iguana_txidfind.c
  17. 18
      iguana/main.c
  18. 2
      includes/iguana_structs.h

4
OSlibs/win/mingw.h

@ -1,12 +1,14 @@
#ifndef MINGW_H
#define MINGW_H
#define ssize_t __int32
#include <io.h>
#define _USE_W32_SOCKETS 1
#include <windows.h>
#include "pthread.h"
#ifndef NATIVE_WINDOWS
#define ENOTCONN WSAENOTCONN
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ENOBUFS WSAENOBUFS
@ -18,7 +20,7 @@
#define EISCONN WSAEISCONN
#define ECONNREFUSED WSAECONNREFUSED
#define EHOSTUNREACH WSAEHOSTUNREACH
#endif
/* winsock doesn't feature poll(), so there is a version implemented
* in terms of select() in mingw.c. The following definitions

29
crypto777/OS_nonportable.c

@ -67,7 +67,7 @@ char *template;
{
static const char letters[]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static gcc_uint64_t value;
static uint64_t value;
#ifdef HAVE_GETTIMEOFDAY
struct timeval tv;
#endif
@ -88,14 +88,14 @@ char *template;
#ifdef HAVE_GETTIMEOFDAY
/* Get some more or less random data. */
gettimeofday (&tv, NULL);
value += ((gcc_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
value += ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
#else
value += getpid ();
#endif
for (count = 0; count < TMP_MAX; ++count)
{
gcc_uint64_t v = value;
uint64_t v = value;
int fd;
/* Fill in the random bits. */
@ -575,10 +575,10 @@ char *OS_nonportable_path(char *str)
return(str);
}
void *OS_nonportable_mapfile(char *fname,uint64_t *filesizep,int32_t enablewrite)
void *OS_nonportable_mapfile(char *fname,long *filesizep,int32_t enablewrite)
{
int32_t fd,rwflags,flags = MAP_FILE|MAP_SHARED;
uint64_t filesize;
long filesize;
void *ptr = 0;
*filesizep = 0;
if ( enablewrite != 0 )
@ -590,7 +590,7 @@ void *OS_nonportable_mapfile(char *fname,uint64_t *filesizep,int32_t enablewrite
return(0);
}
if ( *filesizep == 0 )
filesize = (uint64_t)lseek(fd,0,SEEK_END);
filesize = (long)lseek(fd,0,SEEK_END);
else filesize = *filesizep;
rwflags = PROT_READ;
if ( enablewrite != 0 )
@ -609,13 +609,18 @@ void *OS_nonportable_mapfile(char *fname,uint64_t *filesizep,int32_t enablewrite
int32_t OS_nonportable_renamefile(char *fname,char *newfname)
{
char cmdstr[1024],tmp[512];
char tmp[1024],tmp2[1024];
strcpy(tmp,fname), strcpy(tmp2,newfname);
OS_nonportable_path(tmp), OS_nonportable_path(tmp2);
return((MoveFile(tmp,tmp2) == 0) ? -1 : 0);
}
int32_t OS_nonportable_removefile(char *fname)
{
char tmp[512];
strcpy(tmp,fname);
OS_nonportable_path(tmp);
sprintf(cmdstr,"del %s",tmp);
if ( system(cmdstr) != 0 )
printf("error deleting file.(%s)\n",cmdstr);
else return(1);
OS_portable_path(tmp);
return((DeleteFile(tmp) == 0) ? -1 : 0);
}
int32_t OS_nonportable_launch(char *args[])

24
crypto777/OS_portable.c

@ -30,7 +30,7 @@ void OS_portable_init()
void OS_portable_randombytes(unsigned char *x,long xlen)
{
#ifdef _WIN32
return(OS_nonportable_randombytes(x,xlen));
OS_nonportable_randombytes(x,xlen);
#else
static int fd = -1;
int32_t i;
@ -97,13 +97,7 @@ char *OS_portable_path(char *str)
int32_t OS_portable_renamefile(char *fname,char *newfname)
{
#ifdef _WIN32
char cmdstr[1024],tmp[512];
strcpy(tmp,fname);
OS_portable_path(tmp);
sprintf(cmdstr,"del %s",tmp);
if ( system(cmdstr) != 0 )
printf("error deleting file.(%s)\n",cmdstr);
else return(1);
return(OS_nonportable_renamefile(fname,newfname));
#else
return(rename(fname,newfname));
#endif
@ -112,13 +106,7 @@ int32_t OS_portable_renamefile(char *fname,char *newfname)
int32_t OS_portable_removefile(char *fname)
{
#ifdef _WIN32
char cmdstr[1024],tmp[512];
strcpy(tmp,fname);
OS_portable_path(tmp);
sprintf(cmdstr,"del %s",tmp);
if ( system(cmdstr) != 0 )
printf("error deleting file.(%s)\n",cmdstr);
else return(1);
return(OS_nonportable_removefile(fname));
#else
return(remove(fname));
#endif
@ -131,7 +119,7 @@ int32_t OS_portable_rmdir(char *dirname,int32_t diralso)
strcpy(tmp,dirname);
OS_portable_path(tmp);
#ifdef _WIN32
sprintf(cmdstr,"del %s\*.*",tmp);
sprintf(cmdstr,"rmdir %s",tmp);
if ( system(cmdstr) != 0 )
printf("error deleting dir.(%s)\n",cmdstr);
else return(1);
@ -169,7 +157,7 @@ void *OS_portable_mapfile(char *fname,long *filesizep,int32_t enablewrite)
return(OS_nonportable_mapfile(fname,filesizep,enablewrite));
#else
int32_t fd,rwflags,flags = MAP_FILE|MAP_SHARED;
uint64_t filesize;
long filesize;
void *ptr = 0;
*filesizep = 0;
if ( enablewrite != 0 )
@ -181,7 +169,7 @@ void *OS_portable_mapfile(char *fname,long *filesizep,int32_t enablewrite)
return(0);
}
if ( *filesizep == 0 )
filesize = (uint64_t)lseek(fd,0,SEEK_END);
filesize = (long)lseek(fd,0,SEEK_END);
else filesize = *filesizep;
rwflags = PROT_READ;
if ( enablewrite != 0 )

61
crypto777/OS_portable.h

@ -17,11 +17,18 @@
// iguana_OS has functions that invoke system calls. Whenever possible stdio and similar functions are use and most functions are fully portable and in this file. For things that require OS specific, the call is routed to iguana_OS_portable_* Usually, all but one OS can be handled with the same code, so iguana_OS_portable.c has most of this shared logic and an #ifdef iguana_OS_nonportable.c
#ifdef NATIVE_WINDOWS
//#define uint64_t unsigned __int64
#define PACKED
#else
#define PACKED __attribute__((packed))
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define HAVE_STRUCT_TIMESPEC
#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>
#include <math.h>
@ -30,7 +37,7 @@
#include <sys/types.h>
#include <time.h>
#ifdef __MINGW
#ifdef WIN32
#define sleep(x) Sleep(1000*(x))
#include "../OSlibs/win/mingw.h"
#include "../OSlibs/win/mman.h"
@ -41,19 +48,16 @@
#endif
#else
//#include <sys/poll.h>
#include <time.h>
#include <poll.h>
#include <netdb.h>
#define HAVE_STRUCT_TIMESPEC
#include <pthread.h>
//#include <netinet/in.h>
//#include "in.h"
#include <sys/mman.h>
#include <sys/socket.h>
//#include <winsock2.h>
#define closesocket close
#endif
#ifndef MIN
#define MIN(x, y) ( ((x)<(y))?(x):(y) )
#endif
@ -121,8 +125,8 @@ int32_t hseek(HUFF *hp,int32_t offset,int32_t mode);
#define issue_curl(cmdstr) bitcoind_RPC(0,"curl",cmdstr,0,0,0)
struct allocitem { uint32_t allocsize,type; } __attribute__((packed));
struct queueitem { struct queueitem *next,*prev; uint32_t allocsize,type; } __attribute__((packed));
struct allocitem { uint32_t allocsize,type; } PACKED;
struct queueitem { struct queueitem *next,*prev; uint32_t allocsize,type; } PACKED;
typedef struct queue
{
struct queueitem *list;
@ -194,8 +198,8 @@ void OS_remove_directory(char *dirname);
int32_t OS_portable_renamefile(char *fname,char *newfname);
int32_t OS_portable_removefile(char *fname);
void *OS_portable_mapfile(char *fname,long *filesizep,int32_t enablewrite);
int32_t OS_portable_syncmap(struct OS_mappedptr *mp,long len);
void *OS_portable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);
//int32_t OS_portable_syncmap(struct OS_mappedptr *mp,long len);
//void *OS_portable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);
int32_t is_DST(int32_t datenum);
int32_t extract_datenum(int32_t *yearp,int32_t *monthp,int32_t *dayp,int32_t datenum);
@ -205,31 +209,36 @@ int32_t ecb_decrdate(int32_t *yearp,int32_t *monthp,int32_t *dayp,char *date,int
int32_t conv_date(int32_t *secondsp,char *buf);
uint32_t OS_conv_datenum(int32_t datenum,int32_t hour,int32_t minute,int32_t second);
int32_t OS_conv_unixtime(struct tai *t,int32_t *secondsp,time_t timestamp);
double OS_milliseconds();
void OS_randombytes(uint8_t *x,long xlen);
int32_t OS_truncate(char *fname,long filesize);
char *OS_compatible_path(char *str);
int32_t OS_renamefile(char *fname,char *newfname);
int32_t OS_removefile(char *fname,int32_t scrubflag);
void OS_ensure_directory(char *dirname);
int64_t OS_filesize(char *fname);
int32_t OS_compare_files(char *fname,char *fname2);
int64_t OS_copyfile(char *src,char *dest,int32_t cmpflag);
int32_t OS_releasemap(void *ptr,uint64_t filesize);
void _OS_closemap(struct OS_mappedptr *mp);
void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep);
void *OS_filestr(long *allocsizep,char *fname);
void OS_closemap(struct OS_mappedptr *mp);
long OS_ensurefilesize(char *fname,long filesize,int32_t truncateflag);
int32_t OS_openmap(struct OS_mappedptr *mp);
void *OS_mappedptr(void **ptrp,struct OS_mappedptr *mp,uint64_t allocsize,int32_t rwflag,char *fname);
void *OS_mappedptr(void **ptrp,struct OS_mappedptr *mp,unsigned long allocsize,int32_t rwflag,char *fname);
void *OS_filealloc(struct OS_mappedptr *M,char *fname,struct OS_memspace *mem,long size);
void *OS_nonportable_mapfile(char *fname,long *filesizep,int32_t enablewrite);
int32_t OS_nonportable_removefile(char *fname);
unsigned long OS_filesize(char *fname);
void OS_ensure_directory(char *dirname);
long OS_ensurefilesize(char *fname,long filesize,int32_t truncateflag);
int32_t OS_truncate(char *fname,long filesize);
int32_t OS_renamefile(char *fname,char *newfname);
int32_t OS_removefile(char *fname,int32_t scrubflag);
void *OS_mapfile(char *fname,long *filesizep,int32_t enablewrite);
void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep);
void *OS_filestr(long *allocsizep,char *fname);
int32_t OS_releasemap(void *ptr,unsigned long filesize);
double OS_milliseconds();
void OS_randombytes(uint8_t *x,long xlen);
int32_t OS_syncmap(struct OS_mappedptr *mp,long len);
void *OS_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);
//int32_t OS_syncmap(struct OS_mappedptr *mp,long len);
//void *OS_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);
long myallocated(uint8_t type,long change);
void *mycalloc(uint8_t type,int32_t n,long itemsize);
@ -349,7 +358,7 @@ void SaM_PrepareIndices();
// iguana_serdes.c
#define IGUANA_LOG2PACKETSIZE 21
#define IGUANA_MAXPACKETSIZE (1 << IGUANA_LOG2PACKETSIZE)
struct iguana_msghdr { uint8_t netmagic[4]; char command[12]; uint8_t serdatalen[4],hash[4]; } __attribute__((packed));
struct iguana_msghdr { uint8_t netmagic[4]; char command[12]; uint8_t serdatalen[4],hash[4]; } PACKED;
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
int32_t iguana_validatehdr(char *symbol,struct iguana_msghdr *H);

2
crypto777/SaM.c

@ -46,7 +46,7 @@ struct SaM_info { bits384 bits; TRIT trits[SAM_STATE_SIZE],hash[SAM_HASH_SIZE];
struct SaMhdr { bits384 sig; uint32_t timestamp,nonce; uint8_t numrounds,leverage; };
void SaM_Initialize(struct SaM_info *state);
int32_t SaM_Absorb(struct SaM_info *state,const uint8_t *input,const uint32_t inputSize,const uint8_t *input2,const uint32_t inputSize2);
int32_t SaM_Absorb(struct SaM_info *state,const uint8_t *input,uint32_t inputSize,const uint8_t *input2,uint32_t inputSize2);
bits384 SaM_emit(struct SaM_info *state);
bits384 SaM_encrypt(uint8_t *dest,uint8_t *src,int32_t len,bits384 password,uint32_t timestamp);
uint64_t SaM_threshold(int32_t leverage);

123
crypto777/iguana_OS.c

@ -584,9 +584,9 @@ void OS_ensure_directory(char *dirname)
} else fclose(fp);//, printf("%s exists\n",fname);
}
int64_t OS_filesize(char *fname)
unsigned long OS_filesize(char *fname)
{
FILE *fp; uint64_t fsize = 0;
FILE *fp; unsigned long fsize = 0;
if ( (fp= fopen(fname,"rb")) != 0 )
{
fseek(fp,0,SEEK_END);
@ -641,7 +641,7 @@ int64_t OS_copyfile(char *src,char *dest,int32_t cmpflag)
return(len);
}
int32_t OS_releasemap(void *ptr,uint64_t filesize)
int32_t OS_releasemap(void *ptr,unsigned long filesize)
{
int32_t retval;
if ( ptr == 0 )
@ -728,7 +728,7 @@ long OS_ensurefilesize(char *fname,long filesize,int32_t truncateflag)
int32_t OS_openmap(struct OS_mappedptr *mp)
{
uint64_t allocsize = mp->allocsize;
unsigned long allocsize = mp->allocsize;
if ( mp->actually_allocated != 0 )
{
if ( mp->fileptr == 0 )
@ -757,9 +757,9 @@ int32_t OS_openmap(struct OS_mappedptr *mp)
return(0);
}
void *OS_mappedptr(void **ptrp,struct OS_mappedptr *mp,uint64_t allocsize,int32_t rwflag,char *fname)
void *OS_mappedptr(void **ptrp,struct OS_mappedptr *mp,unsigned long allocsize,int32_t rwflag,char *fname)
{
uint64_t filesize;
unsigned long filesize;
mp->actually_allocated = 0;//!os_supports_mappedfiles();
if ( fname != 0 )
{
@ -876,7 +876,7 @@ void *OS_mapfile(char *fname,long *filesizep,int32_t enablewrite) // win and pna
return(OS_portable_mapfile(fname,filesizep,enablewrite));
}
int32_t OS_syncmap(struct OS_mappedptr *mp,long len) // pnacl doesnt implement sync
/*int32_t OS_syncmap(struct OS_mappedptr *mp,long len) // pnacl doesnt implement sync
{
return(OS_portable_syncmap(mp,len));
}
@ -884,7 +884,7 @@ int32_t OS_syncmap(struct OS_mappedptr *mp,long len) // pnacl doesnt implement s
void *OS_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize) // no syncmap no tmpalloc
{
return(OS_portable_tmpalloc(dirname,name,mem,origsize));
}
}*/
void OS_init()
{
@ -893,7 +893,7 @@ void OS_init()
decode_hex(GENESIS_PUBKEY.bytes,sizeof(GENESIS_PUBKEY),GENESIS_PUBKEYSTR);
decode_hex(GENESIS_PRIVKEY.bytes,sizeof(GENESIS_PRIVKEY),GENESIS_PRIVKEYSTR);
SaM_PrepareIndices();
return(OS_portable_init());
OS_portable_init();
}
int32_t OS_getline(int32_t waitflag,char *line,int32_t max,char *dispstr)
@ -931,3 +931,108 @@ int32_t OS_getline(int32_t waitflag,char *line,int32_t max,char *dispstr)
line[strlen(line)-1] = 0;
return((int32_t)strlen(line));
}
//////////// test suite for:
/*
int64_t OS_filesize(char *fname);
void OS_ensure_directory(char *dirname);
long OS_ensurefilesize(char *fname,long filesize,int32_t truncateflag);
int32_t OS_truncate(char *fname,long filesize);
int32_t OS_renamefile(char *fname,char *newfname);
int32_t OS_removefile(char *fname,int32_t scrubflag);
void *OS_mapfile(char *fname,long *filesizep,int32_t enablewrite);
int32_t OS_releasemap(void *ptr,uint64_t filesize);
double OS_milliseconds();
void OS_randombytes(uint8_t *x,long xlen);
*/
int32_t iguana_OStests()
{
static uint16_t pairs[0x100][0x100],mappairs[0x100][0x100];
uint8_t buf[4096],*bufptr; int32_t val,min,minij,maxij,max,i,j,histo[0x100],retval = 0,n=0; double startmilli,endmilli; FILE *fp; char *name,*name2,*dirname; long filesize; void *fileptr;
startmilli = OS_milliseconds();
printf("\n>>>>>>>>>> starting tests. Please count the seconds (or use stopwatch)\n");
name = "OStests";
name2 = "OStests2";
dirname = "tmp";
fp = fopen(name,"wb");
memset(histo,0,sizeof(histo));
memset(pairs,0,sizeof(pairs));
memset(mappairs,0,sizeof(mappairs));
for (i=0; i<4096; i++)
{
OS_randombytes(buf,sizeof(buf));
for (j=0; j<sizeof(buf); j++)
{
if ( (n++ % 100000) == 0 )
printf("%02x ",buf[j]);
if ( fp != 0 )
fputc(buf[j],fp);
histo[buf[j]]++;
if ( j > 0 )
pairs[buf[j-1]][buf[j]]++;
}
}
fclose(fp);
printf("\nend of random bytes\n\n");
if ( OS_filesize(name) != n )
printf("FAIL OS_filesize %lld != %d error and if OS_filesize doesnt work, nothing else will work\n",(long long)OS_filesize(name),n), retval--;
else
{
printf("PASS OS_filesize.(%s) matches %d\n",name,n);
OS_renamefile(name,name2);
if ( OS_filesize(name2) != n )
printf("FAIL OS_renamefile returns filesize %lld != %d\n",(long long)OS_filesize(name2),n), retval--;
else printf("PASS OS_renamefile (%s) -> (%s) worked\n",name,name2);
if ( (fileptr= OS_mapfile(name2,&filesize,0)) == 0 )
printf("FAIL OS_mapfile.(%s) returns null\n",name2), retval--;
else if ( filesize != n )
printf("FAIL OS_mapfile.(%s) returns %ld != %d\n",name2,filesize,n), retval--;
else
{
bufptr = fileptr;
for (i=0; i<4096; i++)
{
memcpy(buf,bufptr,sizeof(buf));
bufptr += sizeof(buf);
for (j=1; j<sizeof(buf); j++)
mappairs[buf[j-1]][buf[j]]++;
}
if ( memcmp(pairs,mappairs,sizeof(pairs)) != 0 )
printf("FAIL OS_mapfile.(%s) %ld data error pairs[][] != mappairs[][]\n",name2,filesize), retval--;
else printf("PASS OS_mapfile.(%s) %ld regenerated identical pairs[][]\n",name2,filesize);
if ( OS_releasemap(fileptr,filesize) != 0 )
printf("FAIL OS_releasemap.(%s) %ld returns error\n",name2,filesize), retval--;
else printf("PASS OS_releasemap.(%s) %ld returns success\n",name2,filesize);
}
OS_removefile(name2,0);
if ( OS_filesize(name2) == n )
printf("FAIL OS_removefile.(%s) didnt work\n",name2), retval--;
else if ( (fp= fopen(name2,"rb")) != 0 )
printf("FAIL OS_removefile.(%s) didnt work fopen fp.%p\n",name2,fp), fclose(fp), retval--;
else printf("PASS OS_removefile.(%s) worked\n",name2);
}
minij = min = (1 << 30);
maxij = max = -1;
for (i=0; i<0x100; i++)
{
if ( (val= histo[i]) > max )
max = val;
else if ( val < min )
min = val;
for (j=0; j<0x100; j++)
{
if ( (val= pairs[i][j]) > maxij )
maxij = val;
else if ( val < minij )
minij = val;
}
}
endmilli = OS_milliseconds();
printf("\n\nDid that take %.3f seconds? If not, there is a problem with OS_milliseconds\n\nMake sure above numbers look random and the min/max are within specified range:\n<3%% %.2f%% min %d max %d | <75%% %.3f%% minij %d maxij %d\n",(endmilli - startmilli)/1000.,100*(double)max/min - 100.,min,max,100*(double)maxij/minij - 100.,minij,maxij);
return(retval);
}

2
crypto777/inet.c

@ -24,7 +24,9 @@
#ifdef _WIN32
#define in6_addr sockaddr
#define in_addr_t struct sockaddr_storage
#ifndef NATIVE_WINDOWS
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#endif
struct sockaddr_in6 {
short sin6_family;

2
crypto777/jpeg/jmemsys.h

@ -154,7 +154,7 @@ typedef struct backing_store_struct {
/* For the MS-DOS manager (jmemdos.c), we need: */
handle_union handle; /* reference to backing-store storage object */
char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
short temp_file;
FILE *temp_file;
#else
#ifdef USE_MAC_MEMMGR
/* For the Mac manager (jmemmac.c), we need: */

2
iguana/iguana_bundles.c

@ -1028,7 +1028,7 @@ int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *c
int32_t i; struct iguana_bundle *tmpbp; struct iguana_blockreq *breq;
if ( coin->firstRTheight == 0 && iguana_bundleready(myinfo,coin,bp,0) == bp->n )
{
printf(">>>>>>>>>>>>>> EMIT.[%3d] %s | 1st.%-3d h.%-3d c.%-3d s.[%3d] maxB.%d NET.(h%d b%d) %ld:%02ld\n",bp->hdrsi,coin->symbol,coin->current!=0?coin->current->hdrsi:-1,coin->current!=0?coin->current->numhashes:-1,coin->current!=0?coin->current->numcached:-1,coin->current!=0?coin->current->numsaved:-1,coin->MAXBUNDLES,HDRnet,queue_size(&coin->priorityQ),(time(NULL)-coin->startutc)/60,(time(NULL)-coin->startutc)%60);
printf(">>>>>>>>>>>>>> EMIT.[%3d] %s | 1st.%-3d h.%-3d c.%-3d s.[%3d] maxB.%d NET.(h%d b%d) %u:%02u\n",bp->hdrsi,coin->symbol,coin->current!=0?coin->current->hdrsi:-1,coin->current!=0?coin->current->numhashes:-1,coin->current!=0?coin->current->numcached:-1,coin->current!=0?coin->current->numsaved:-1,coin->MAXBUNDLES,HDRnet,queue_size(&coin->priorityQ),(uint32_t)(time(NULL)-coin->startutc)/60,(uint32_t)(time(NULL)-coin->startutc)%60);
if ( queue_size(&coin->priorityQ) > 10000 )
{
while ( (breq= queue_dequeue(&coin->priorityQ,0)) != 0 )

2
iguana/iguana_init.c

@ -459,7 +459,7 @@ void iguana_coinpurge(struct iguana_info *coin)
coin->started = 0;
while ( coin->idletime == 0 && coin->emitbusy > 0 )
{
printf("coinpurge.%s waiting for idle %lu emitbusy.%d\n",coin->symbol,time(NULL),coin->emitbusy);
printf("coinpurge.%s waiting for idle %u emitbusy.%d\n",coin->symbol,(uint32_t)time(NULL),coin->emitbusy);
sleep(1);
}
coin->RTgenesis = 0;

10
iguana/iguana_peers.c

@ -361,14 +361,14 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
}
saddr.sin_family = AF_INET;
saddr.sin_port = htons(port);
#ifdef WIN32
saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1");
#else
//#ifdef WIN32
// saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1");
//#else
memcpy(&saddr.sin_addr.s_addr,hostent->h_addr_list[0],hostent->h_length);
expand_ipbits(checkipaddr,saddr.sin_addr.s_addr);
if ( strcmp(ipaddr,checkipaddr) != 0 )
printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)?\n",bindflag,checkipaddr,ipaddr);
#endif
//#endif
if ( (sock= socket(AF_INET,SOCK_STREAM,0)) < 0 )
{
if ( errno != ETIMEDOUT )
@ -378,6 +378,7 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
opt = 1;
slen = sizeof(opt);
//printf("set keepalive.%d\n",setsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,(void *)&opt,slen));
#ifndef WIN32
if ( 1 )//&& bindflag != 0 )
{
if ( 1 )
@ -393,6 +394,7 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
} else setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(void *)&opt,sizeof(opt));
#ifdef __APPLE__
setsockopt(sock,SOL_SOCKET,SO_NOSIGPIPE,&opt,sizeof(opt));
#endif
#endif
if ( bindflag == 0 )
{

24
iguana/iguana_ramchain.c

@ -178,7 +178,7 @@ uint32_t iguana_ramchain_addtxid(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
{
if ( t->txidind != txidind || memcmp(t->txid.bytes,txid.bytes,sizeof(bits256)) != 0 || t->numvouts != numvouts || t->numvins != numvins || t->firstvout != ramchain->H.unspentind || t->firstvin != ramchain->H.spendind || t->locktime != locktime || t->version != version || t->timestamp != timestamp )
{
printf("iguana_ramchain_addtxid.RO: addtxid mismatch (%d %d %d %d %d) vs. (%d %d %d %d %d)\n",t->txidind,t->numvouts,t->numvins,t->firstvout,t->firstvin,txidind,numvouts,numvins,ramchain->H.unspentind,ramchain->H.spendind);
printf("iguana_ramchain_addtxid.RO: addtxid mismatch (%u %d %d %u %u) vs. (%d %d %d %d %d)\n",(uint32_t)t->txidind,t->numvouts,t->numvins,(uint32_t)t->firstvout,(uint32_t)t->firstvin,txidind,numvouts,numvins,ramchain->H.unspentind,ramchain->H.spendind);
//getchar();
return(0);
}
@ -193,7 +193,7 @@ uint32_t iguana_ramchain_addtxid(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
t->locktime = locktime, t->version = version, t->timestamp = timestamp;
if ( t->txidind != txidind || t->firstvout != ramchain->H.unspentind || t->firstvin != ramchain->H.spendind || t->bundlei != bundlei )
{
printf("addtxid error: t->txidind %u != %u txidind || t->firstvout %u != %u ramchain->H.unspentind || t->firstvin %u != %u ramchain->H.spendind || t->bundlei %u != %u bundlei\n",t->txidind,txidind,t->firstvout,ramchain->H.unspentind,t->firstvin,ramchain->H.spendind,t->bundlei,bundlei);
printf("addtxid error: t->txidind %u != %u txidind || t->firstvout %u != %u ramchain->H.unspentind || t->firstvin %u != %u ramchain->H.spendind || t->bundlei %u != %u bundlei\n",(uint32_t)t->txidind,txidind,(uint32_t)t->firstvout,ramchain->H.unspentind,(uint32_t)t->firstvin,ramchain->H.spendind,(uint32_t)t->bundlei,bundlei);
return(0);
}
if ( ramchain->expanded != 0 && (rdata= ramchain->H.data) != 0 )
@ -568,7 +568,7 @@ uint32_t iguana_ramchain_addspend256(struct iguana_info *coin,struct iguana_peer
{
if ( vinscriptlen != s->vinscriptlen || s->sequenceid != sequence || memcmp(s->prevhash2.bytes,prev_hash.bytes,sizeof(bits256)) != 0 || s->prevout != prev_vout ) //|| s->hdrsi != hdrsi
{
char str[65],str2[65]; printf("check offset %llu (%d %d) addspend.%d v %d RO value mismatch sequenceid.%x seq.%x prev_vout(%d vs %d) %s vs %s\n",(long long)s->scriptpos,vinscriptlen,s->vinscriptlen,spendind,s->spendind,s->sequenceid,sequence,s->prevout,prev_vout,bits256_str(str,s->prevhash2),bits256_str(str2,prev_hash));
char str[65],str2[65]; printf("check offset %llu (%d %d) addspend.%d v %d RO value mismatch sequenceid.%x seq.%x prev_vout(%d vs %d) %s vs %s\n",(long long)s->scriptpos,vinscriptlen,(int32_t)s->vinscriptlen,spendind,s->spendind,s->sequenceid,sequence,s->prevout,prev_vout,bits256_str(str,s->prevhash2),bits256_str(str2,prev_hash));
//printf("check addspend.%d vs %d RO value mismatch (%d %d:%d) vs (%d %d:%d)\n",spendind,s->spendind,s->prevout,s->hdrsi,s->bundlei,prev_vout,hdrsi,bundlei);
//exit(-1);
return(0);
@ -599,7 +599,7 @@ uint32_t iguana_ramchain_addspend256(struct iguana_info *coin,struct iguana_peer
//else printf("spend256 scriptfpos.%d\n",s->scriptfpos);
char str[65];
if ( 0 && coin->virtualchain != 0 )
printf("W.%p s.%d vout.%d/%d [%d] %s fpos.%u slen.%d\n",s,spendind,s->prevout,prev_vout,bp->hdrsi,bits256_str(str,prev_hash),(uint32_t)s->scriptpos,s->vinscriptlen);
printf("W.%p s.%d vout.%d/%d [%d] %s fpos.%u slen.%d\n",s,spendind,s->prevout,prev_vout,bp->hdrsi,bits256_str(str,prev_hash),(uint32_t)s->scriptpos,(int32_t)s->vinscriptlen);
}
return(spendind);
}
@ -1093,18 +1093,18 @@ int32_t iguana_ramchain_verify(struct iguana_info *coin,struct iguana_ramchain *
t = &T[ramchain->H.txidind];
if ( t->txidind != ramchain->H.txidind )
{
printf("firsti.%d t->txidind.%d != txidind.%d\n",rdata->firsti,t->txidind,ramchain->H.txidind);
printf("firsti.%d t->txidind.%u != txidind.%u\n",rdata->firsti,(uint32_t)t->txidind,(uint32_t)ramchain->H.txidind);
return(-1);
}
if ( t->firstvout != ramchain->H.unspentind )
{
printf("%p txidind.%d firstvout.%d != unspentind.%d\n",t,ramchain->H.txidind,t->firstvout,ramchain->H.unspentind);
printf("%p txidind.%u firstvout.%u != unspentind.%u\n",t,(uint32_t)ramchain->H.txidind,(uint32_t)t->firstvout,(uint32_t)ramchain->H.unspentind);
//exit(-1);
return(-4);
}
if ( t->firstvin != ramchain->H.spendind )
{
printf("t[%d] firstvin.%d vs spendind.%d\n",t->txidind,t->firstvin,ramchain->H.spendind);
printf("t[%u] firstvin.%u vs spendind.%d\n",(uint32_t)t->txidind,(uint32_t)t->firstvin,ramchain->H.spendind);
return(-5);
}
if ( ramchain->expanded != 0 )
@ -2039,7 +2039,7 @@ void iguana_ramchain_disp(struct iguana_ramchain *ramchain)
init_hexbytes_noT(str,U[unspentind].rmd160,20);
printf("(%.8f %s) ",dstr(U[unspentind].value),str);
}
printf("txid.[%d] %s (%d:%d %d:%d)\n",txidind,bits256_str(str,tx->txid),tx->firstvout,tx->numvouts,tx->firstvin,tx->numvins);
printf("txid.[%d] %s (%u:%d %u:%d)\n",txidind,bits256_str(str,tx->txid),(uint32_t)tx->firstvout,tx->numvouts,(uint32_t)tx->firstvin,tx->numvins);
}
}
}
@ -2056,8 +2056,10 @@ void iguana_blockdelete(struct iguana_info *coin,bits256 hash2,int32_t i)
if ( fname[0] != 0 )
{
OS_removefile(fname,0);
#ifndef WIN32
strcat(fname,".tmp");
OS_removefile(fname,0);
#endif
}
}
@ -2143,12 +2145,14 @@ void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,str
else
{
fclose(fp);
#ifndef WIN32
if ( renameflag != 0 )
{
sprintf(renamed,"%s.tmp",fname);
OS_renamefile(fname,renamed);
strcpy(fname,renamed);
}
#endif
if ( (ptr= OS_mapfile(fname,filesizep,0)) == 0 )
{
printf("error mapping.(%s) bundlei.%d\n",fname,bundlei);
@ -2700,7 +2704,7 @@ int32_t iguana_bundlemergeHT(struct supernet_info *myinfo,char *fname,struct igu
{
if ( iguana_ramchain_alloc(fname,coin,dest,mem,&HASHMEM,(A->H.data->numtxids+B->H.data->numtxids),(A->H.data->numunspents+B->H.data->numunspents),(A->H.data->numspends+B->H.data->numspends),(A->H.data->numpkinds+B->H.data->numpkinds),(A->H.data->numexternaltxids+B->H.data->numexternaltxids),A->H.data->scriptspace,A->height,A->numblocks + B->numblocks,coin->chain->zcash) < 0 )
{
printf("depth.%d ht.%d fsize.%s ERROR alloc lag.%d elapsed.%ld\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),now-starttime,time(NULL)-now);
printf("depth.%d ht.%d fsize.%s ERROR alloc lag.%d elapsed.%d\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),now-starttime,(int32_t)(time(NULL)-now));
iguana_mergefree(coin,mem,A,B,&HASHMEM,&HASHMEMA,&HASHMEMB);
return(-1);
}
@ -2717,7 +2721,7 @@ int32_t iguana_bundlemergeHT(struct supernet_info *myinfo,char *fname,struct igu
else if ( iguana_ramchain_expandedsave(myinfo,coin,RAMCHAIN_DESTARG,&newchain,&HASHMEM,0,0) == 0 )
{
printf("merging isnt setup to save the blockROs\n");
printf("depth.%d ht.%d fsize.%s MERGED %d[%d] and %d[%d] lag.%d elapsed.%ld bp.%d -> %d\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),A->height,A->numblocks,B->height,B->numblocks,now-starttime,time(NULL)-now,bp->bundleheight,nextbp->bundleheight);
printf("depth.%d ht.%d fsize.%s MERGED %d[%d] and %d[%d] lag.%d elapsed.%d bp.%d -> %d\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),A->height,A->numblocks,B->height,B->numblocks,now-starttime,(int32_t)(time(NULL)-now),bp->bundleheight,nextbp->bundleheight);
iguana_mergefree(coin,mem,A,B,&HASHMEM,&HASHMEMA,&HASHMEMB);
bp->mergefinish = 0;
nextbp->mergefinish = (uint32_t)time(NULL);

2
iguana/iguana_recv.c

@ -1596,7 +1596,7 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
if ( time(NULL) > bp->issuetime+lag )
{
if ( 0 && bp == coin->current )
printf("LAG.%ld hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",time(NULL)-bp->hdrtime,i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount);
printf("LAG.%d hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",(uint32_t)(time(NULL)-bp->hdrtime),i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount);
if ( bp->issuetime == 0 )
coin->numpendings++;
init_hexbytes_noT(hashstr,bp->hashes[0].bytes,sizeof(bits256));

4
iguana/iguana_spendvectors.c

@ -294,7 +294,7 @@ int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coi
now = (uint32_t)time(NULL);
if ( txidind != T[txidind].txidind || spendind != T[txidind].firstvin )
{
printf("spendvectors: txidind %u != %u nextT[txidind].firsttxidind || spendind %u != %u nextT[txidind].firstvin\n",txidind,T[txidind].txidind,spendind,T[txidind].firstvin);
printf("spendvectors: txidind %u != %u nextT[txidind].firsttxidind || spendind %u != %u nextT[txidind].firstvin\n",txidind,(uint32_t)T[txidind].txidind,spendind,(uint32_t)T[txidind].firstvin);
myfree(ptr,sizeof(*ptr) * n);
return(-1);
}
@ -496,7 +496,7 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig
now = (uint32_t)time(NULL);
if ( txidind != T[txidind].txidind || spendind != T[txidind].firstvin || unspentind != T[txidind].firstvout )
{
printf("balancegen: txidind %u != %u T[txidind].firsttxidind || spendind %u != %u T[txidind].firstvin errs.%d (%d %d)\n",txidind,T[txidind].txidind,spendind,T[txidind].firstvin,errs,unspentind,B[i].firstvout);
printf("balancegen: txidind %u != %u T[txidind].firsttxidind || spendind %u != %u T[txidind].firstvin errs.%d (%d %d)\n",txidind,(uint32_t)T[txidind].txidind,spendind,(uint32_t)T[txidind].firstvin,errs,unspentind,B[i].firstvout);
return(-1);
}
if ( 0 && bp == coin->current )

2
iguana/iguana_tx.c

@ -82,7 +82,7 @@ int32_t iguana_vinset(struct iguana_info *coin,uint8_t *scriptspace,int32_t heig
{
iguana_vinsfname(coin,bp->ramchain.from_ro,fname,s->fileid);
if ( (scriptlen= iguana_scriptdata(coin,scriptspace,coin->vinptrs[s->fileid],fname,s->scriptpos,s->scriptlen)) != s->scriptlen )
printf("err.%d getting %d bytes from fileid.%llu[%d] %s for s%d\n",err,s->scriptlen,(long long)s->scriptpos,s->fileid,fname,spendind);
printf("err.%d getting %d bytes from fileid.%u[%u] %s for s%d\n",err,(int32_t)s->scriptlen,(uint32_t)s->scriptpos,(uint32_t)s->fileid,fname,spendind);
}
vin->scriptlen = s->scriptlen;
vin->vinscript = scriptspace;

4
iguana/iguana_txidfind.c

@ -316,7 +316,7 @@ struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,st
if ( j < bp->n )
{
if ( j != T[txidind].bundlei )
printf("bundlei mismatch j.%d != %d\n",j,T[txidind].bundlei);
printf("bundlei mismatch j.%d != %u\n",j,(uint32_t)T[txidind].bundlei);
else
{
*heightp = bp->bundleheight + T[txidind].bundlei;
@ -335,7 +335,7 @@ struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,st
return(tx);
}
}
char str[65],str2[65]; printf("iguana_txidfind mismatch.[%d:%d] %d %s vs %s\n",bp->hdrsi,T[txidind].extraoffset,txidind,bits256_str(str,txid),bits256_str(str2,T[txidind].txid));
char str[65],str2[65]; printf("iguana_txidfind mismatch.[%d:%u] %d %s vs %s\n",bp->hdrsi,(uint32_t)T[txidind].extraoffset,txidind,bits256_str(str,txid),bits256_str(str2,T[txidind].txid));
return(0);
}
}

18
iguana/main.c

@ -1543,7 +1543,7 @@ void iguana_relays_init(struct supernet_info *myinfo)
void iguana_main(void *arg)
{
int32_t usessl = 0, ismainnet = 1; struct supernet_info *myinfo; //cJSON *argjson = 0;
int32_t usessl = 0, ismainnet = 1, do_OStests = 0; struct supernet_info *myinfo;
if ( (IGUANA_BIGENDIAN= iguana_isbigendian()) > 0 )
printf("BIGENDIAN\n");
else if ( IGUANA_BIGENDIAN == 0 )
@ -1556,13 +1556,17 @@ void iguana_main(void *arg)
iguana_Qinit();
myinfo = SuperNET_MYINFO(0);
libgfshare_init(myinfo,myinfo->logs,myinfo->exps);
//void test_mimblewimble(void *ctx);
//test_mimblewimble(myinfo->ctx);
if ( 0 )
if ( arg != 0 && strcmp((char *)arg,"OStests") == 0 )
do_OStests = 1;
#ifdef IGUANA_OSTESTS
do_OStests = 1;
#endif
if ( do_OStests != 0 )
{
int32_t i; for (i=0; i<10; i++)
iguana_schnorr(myinfo);
getchar();
int32_t iguana_OStests();
int32_t retval = iguana_OStests();
printf("OStests retval %d\n",retval);
return;
}
myinfo->rpcport = IGUANA_RPCPORT;
strcpy(myinfo->rpcsymbol,"BTCD");

2
includes/iguana_structs.h

@ -16,7 +16,7 @@
#ifndef H_IGUANASTRUCTS_H
#define H_IGUANASTRUCTS_H
#ifdef __WIN32
#ifdef WIN32
#define PACKEDSTRUCT
#else
#define PACKEDSTRUCT __attribute__((packed))

Loading…
Cancel
Save