Browse Source

Merge pull request #136 from fadedreamz/windev-headless

Changes for iguana source for windows platform (32bit and 64bit)
etomic
jl777 8 years ago
committed by GitHub
parent
commit
6b01f3648b
  1. 2
      .gitignore
  2. 36
      OSlibs/win/mingw.h
  3. BIN
      OSlibs/win/nanomsg.dll
  4. BIN
      OSlibs/win/nanomsg.lib
  5. BIN
      OSlibs/win/x64/nanomsg.dll
  6. BIN
      OSlibs/win/x64/nanomsg.lib
  7. 17
      crypto777/OS_nonportable.c
  8. 9
      crypto777/iguana_OS.c
  9. 2
      crypto777/nanosrc/nn_config.h
  10. 28
      iguana.sln
  11. 9
      iguana.vcxproj
  12. 1
      iguana.vcxproj.filters
  13. 3
      iguana/iguana777.h
  14. 40
      iguana/iguana_accept.c
  15. 13
      iguana/iguana_blocks.c
  16. 9
      iguana/iguana_init.c
  17. 64
      iguana/iguana_peers.c
  18. 29
      iguana/iguana_ramchain.c
  19. 34
      iguana/iguana_tx.c
  20. 10
      iguana/iguana_txidfind.c
  21. 1
      includes/iguana_defines.h
  22. 9
      includes/iguana_funcs.h
  23. 20
      includes/iguana_structs.h

2
.gitignore

@ -1,4 +1,4 @@
x64
*.o *.o
agents/iguana.exe agents/iguana.exe
Debug/* Debug/*

36
OSlibs/win/mingw.h

@ -28,18 +28,52 @@
* are copied from linux man pages. A poll() macro is defined to * are copied from linux man pages. A poll() macro is defined to
* call the version in mingw.c. * call the version in mingw.c.
*/ */
#define POLLIN 0x0001 /* There is data to read */
#define POLLPRI 0x0002 /* There is urgent data to read */ #define POLLPRI 0x0002 /* There is urgent data to read */
#if defined(_M_X64)
/*
* when we are using WSAPoll() with window's struct pollfd struct
* we need to update the value for POLLIN and POLLOUT according to window's
* WSAPoll() return values
* @author - fadedreamz@gmail.com
*/
//TODO: need to update other values to match with WSAPoll() function
#define POLLIN POLLRDNORM | POLLRDBAND /* There is data to read */
#define POLLOUT POLLWRNORM /* Writing now will not block */
#else
#define POLLIN 0x0001 /* There is data to read */
#define POLLOUT 0x0004 /* Writing now will not block */ #define POLLOUT 0x0004 /* Writing now will not block */
#endif
#define POLLERR 0x0008 /* Error condition */ #define POLLERR 0x0008 /* Error condition */
#define POLLHUP 0x0010 /* Hung up */ #define POLLHUP 0x0010 /* Hung up */
#define POLLNVAL 0x0020 /* Invalid request: fd not open */ #define POLLNVAL 0x0020 /* Invalid request: fd not open */
/**
* we want to use mingw provided pollfd if and only if we are compiling this
* in windows 32bit but exclude it when we are compiling it in win 64
*
* @author - fadedreamz@gmail.com
* @remarks - #if (defined(_M_X64) || defined(__amd64__)) && defined(WIN32)
* is equivalent to #if defined(_M_X64) as _M_X64 is defined for MSVC only
*/
#if !defined(_M_X64)
struct pollfd { struct pollfd {
SOCKET fd; /* file descriptor */ SOCKET fd; /* file descriptor */
short events; /* requested events */ short events; /* requested events */
short revents; /* returned events */ short revents; /* returned events */
}; };
#endif
#if defined(_M_X64)
/*
* we want to use the window's poll function if poll() is invoked in win64
* as we are using window's pollfd struct when we are using x64
* @author - fadedreamz@gmail.com
*/
#define poll(x, y, z) WSAPoll(x, y, z)
#else
#define poll(x, y, z) win32_poll(x, y, z) #define poll(x, y, z) win32_poll(x, y, z)
#endif
/* These wrappers do nothing special except set the global errno variable if /* These wrappers do nothing special except set the global errno variable if
* an error occurs (winsock doesn't do this by default). They set errno * an error occurs (winsock doesn't do this by default). They set errno

BIN
OSlibs/win/nanomsg.dll

Binary file not shown.

BIN
OSlibs/win/nanomsg.lib

Binary file not shown.

BIN
OSlibs/win/x64/nanomsg.dll

Binary file not shown.

BIN
OSlibs/win/x64/nanomsg.lib

Binary file not shown.

17
crypto777/OS_nonportable.c

@ -13,6 +13,23 @@
* * * *
******************************************************************************/ ******************************************************************************/
/**
* - we need to include WinSock2.h header to correctly use windows structure
* as the application is still using 32bit structure from mingw so, we need to
* add the include based on checking
*
* @author - fadedreamz@gmail.com
* @remarks - #if (defined(_M_X64) || defined(__amd64__)) && defined(WIN32)
* is equivalent to #if defined(_M_X64) as _M_X64 is defined for MSVC only
*
* @remarks - we need this because in win64 we are using windows provided pollfd structure
* not from the mingw header, so we need to include the windows header
* if we are compiling in windows 64bit
*/
#if defined(_M_X64)
#define WIN32_LEAN_AND_MEAN
#include <WinSock2.h>
#endif
#include "OS_portable.h" #include "OS_portable.h"

9
crypto777/iguana_OS.c

@ -446,7 +446,16 @@ void *iguana_memalloc(struct OS_memspace *mem,long size,int32_t clearflag)
#endif #endif
if ( (mem->used + size) <= mem->totalsize ) if ( (mem->used + size) <= mem->totalsize )
{ {
/*
* solution to calculate memory address in a portable way
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
ptr = (void *)((unsigned char *)mem->ptr + mem->used);
#else
ptr = (void *)(long)(((long)mem->ptr + mem->used)); ptr = (void *)(long)(((long)mem->ptr + mem->used));
#endif
mem->used += size; mem->used += size;
if ( size*clearflag != 0 ) if ( size*clearflag != 0 )
memset(ptr,0,size); memset(ptr,0,size);

2
crypto777/nanosrc/nn_config.h

@ -54,11 +54,13 @@ void PNACL_message(const char* format, ...);
#include <glibc-compat/sys/uio.h> #include <glibc-compat/sys/uio.h>
#include <glibc-compat/sys/un.h> #include <glibc-compat/sys/un.h>
#else #else
#if !defined(WIN32)
//#define NN_ENABLE_EXTRA 1 //#define NN_ENABLE_EXTRA 1
#define PNACL_message printf #define PNACL_message printf
#include <sys/uio.h> #include <sys/uio.h>
#include <sys/un.h> #include <sys/un.h>
#endif #endif
#endif
/* Size of the buffer used for batch-reads of inbound data. To keep the /* Size of the buffer used for batch-reads of inbound data. To keep the
performance optimal make sure that this value is larger than network MTU. */ performance optimal make sure that this value is larger than network MTU. */

28
iguana.sln

@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "iguana", "iguana.vcxproj", "{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Debug|x64.ActiveCfg = Debug|x64
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Debug|x64.Build.0 = Debug|x64
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Debug|x86.ActiveCfg = Debug|Win32
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Debug|x86.Build.0 = Debug|Win32
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Release|x64.ActiveCfg = Release|x64
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Release|x64.Build.0 = Release|x64
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Release|x86.ActiveCfg = Release|Win32
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

9
iguana.vcxproj

@ -92,11 +92,13 @@
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment> <StructMemberAlignment>1Byte</StructMemberAlignment>
<AdditionalIncludeDirectories>.\iguana;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>.\iguana;.\OSlibs\win;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -105,12 +107,14 @@
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;NATIVE_WINDOWS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment> <StructMemberAlignment>1Byte</StructMemberAlignment>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>.\OSlibs\win\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>pthread_lib.lib;Ws2_32.lib;nanomsg.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -260,6 +264,7 @@
<ClCompile Include="iguana\iguana_json.c" /> <ClCompile Include="iguana\iguana_json.c" />
<ClCompile Include="iguana\iguana_mofn.c" /> <ClCompile Include="iguana\iguana_mofn.c" />
<ClCompile Include="iguana\iguana_msg.c" /> <ClCompile Include="iguana\iguana_msg.c" />
<ClCompile Include="iguana\iguana_notary.c" />
<ClCompile Include="iguana\iguana_passport.c" /> <ClCompile Include="iguana\iguana_passport.c" />
<ClCompile Include="iguana\iguana_payments.c" /> <ClCompile Include="iguana\iguana_payments.c" />
<ClCompile Include="iguana\iguana_peers.c" /> <ClCompile Include="iguana\iguana_peers.c" />

1
iguana.vcxproj.filters

@ -102,6 +102,7 @@
<ClCompile Include="iguana\secp256k1\src\secp256k1.c" /> <ClCompile Include="iguana\secp256k1\src\secp256k1.c" />
<ClCompile Include="iguana\SuperNET_keys.c" /> <ClCompile Include="iguana\SuperNET_keys.c" />
<ClCompile Include="OSlibs\win\mingw.c" /> <ClCompile Include="OSlibs\win\mingw.c" />
<ClCompile Include="iguana\iguana_notary.c" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="basilisk\basilisk.h" /> <ClInclude Include="basilisk\basilisk.h" />

3
iguana/iguana777.h

@ -105,7 +105,8 @@ struct supernet_info
struct dpow_info DPOWS[64]; int32_t numdpows,dpowsock,dexsock,pubsock,repsock,subsock,reqsock; struct dpow_info DPOWS[64]; int32_t numdpows,dpowsock,dexsock,pubsock,repsock,subsock,reqsock;
struct delayedPoW_info dPoW; struct delayedPoW_info dPoW;
struct basilisk_spend *spends; int32_t numspends; struct basilisk_spend *spends; int32_t numspends;
//struct peggy_info *PEGS; // fadedreamz
struct peggy_info *PEGS;
void *PAXDATA; void *PAXDATA;
struct liquidity_info linfos[64]; struct liquidity_info linfos[64];
struct komodo_notaries NOTARY; struct komodo_notaries NOTARY;

40
iguana/iguana_accept.c

@ -13,6 +13,19 @@
* * * *
******************************************************************************/ ******************************************************************************/
/**
* - we need to include WinSock2.h header to correctly use windows structure
* as the application is still using 32bit structure from mingw so, we need to
* add the include based on checking
* @author - fadedreamz@gmail.com
* @remarks - #if (defined(_M_X64) || defined(__amd64__)) && defined(WIN32)
* is equivalent to #if defined(_M_X64) as _M_X64 is defined for MSVC only
*/
#if defined(_M_X64)
#define WIN32_LEAN_AND_MEAN
#include <WinSock2.h>
#endif
#include "iguana777.h" #include "iguana777.h"
#include "exchanges777.h" #include "exchanges777.h"
@ -20,10 +33,28 @@ struct iguana_accept { struct queueitem DL; char ipaddr[64]; uint32_t ipbits; in
int32_t iguana_acceptspoll(uint8_t *buf,int32_t bufsize,struct iguana_accept *accepts,int32_t num,int32_t timeout) int32_t iguana_acceptspoll(uint8_t *buf,int32_t bufsize,struct iguana_accept *accepts,int32_t num,int32_t timeout)
{ {
/**
* This solution is for win64
* 2^11*sizeof(struct fd) for win64 bit gives a very big number
* for that reason it cannot allocate memory from stack
* so the solution is to allocate memory from heap, instead of stack
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
struct pollfd * fds;
int32_t i, j, n, r, nonz, flag; struct iguana_accept *ptr;
if (num == 0)
return(0);;
fds = (struct pollfd *) malloc(sizeof(struct pollfd) * IGUANA_MAXPEERS);
if (NULL == fds)
return -1;
memset(fds, 0, sizeof(struct pollfd) * IGUANA_MAXPEERS);
#else
struct pollfd fds[IGUANA_MAXPEERS]; int32_t i,j,n,r,nonz,flag; struct iguana_accept *ptr; struct pollfd fds[IGUANA_MAXPEERS]; int32_t i,j,n,r,nonz,flag; struct iguana_accept *ptr;
if ( num == 0 ) if ( num == 0 )
return(0);; return(0);;
memset(fds,0,sizeof(fds)); memset(fds,0,sizeof(fds));
#endif
flag = 0; flag = 0;
r = (rand() % num); r = (rand() % num);
for (j=n=nonz=0; j<num&&j<sizeof(fds)/sizeof(*fds)-1; j++) for (j=n=nonz=0; j<num&&j<sizeof(fds)/sizeof(*fds)-1; j++)
@ -58,6 +89,15 @@ int32_t iguana_acceptspoll(uint8_t *buf,int32_t bufsize,struct iguana_accept *ac
} }
} }
} }
/**
* graceful memory release, because we allocated memory on heap,
* so we are releasing it here
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
free(fds);
#endif
return(0); return(0);
} }

13
iguana/iguana_blocks.c

@ -313,8 +313,21 @@ int32_t iguana_blockROsize(uint8_t zcash)
void *iguana_blockzcopyRO(uint8_t zcash,struct iguana_blockRO *dest,int32_t desti,struct iguana_blockRO *src,int32_t srci) void *iguana_blockzcopyRO(uint8_t zcash,struct iguana_blockRO *dest,int32_t desti,struct iguana_blockRO *src,int32_t srci)
{ {
int32_t bROsize = iguana_blockROsize(zcash); int32_t bROsize = iguana_blockROsize(zcash);
/**
* The memory address calculation was done in a non-portable way using
* long value which has 4 bytes in 64bit windows (causing invalide memory address)
* due to data truncation,
* the solution is to use portable way to calculate the address
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
dest = (void *)((unsigned char *)dest + desti*bROsize);
src = (void *)((unsigned char *)src + srci*bROsize);
#else
dest = (void *)((long)dest + desti*bROsize); dest = (void *)((long)dest + desti*bROsize);
src = (void *)((long)src + srci*bROsize); src = (void *)((long)src + srci*bROsize);
#endif
memcpy(dest,src,bROsize); memcpy(dest,src,bROsize);
return(src); return(src);
} }

9
iguana/iguana_init.c

@ -612,7 +612,16 @@ struct iguana_info *iguana_coinstart(struct supernet_info *myinfo,struct iguana_
fpos = -1; fpos = -1;
for (j=0; j<2; j++) for (j=0; j<2; j++)
{ {
/**
* macro switch for easy debug from Visual Studio IDE
* @author-fadedreamz@gmail.com
*/
#if defined(WIN32) && defined(_DEBUG)
sprintf(fname, "%s/%s/%s_%s%s.txt", "iguana", GLOBAL_CONFSDIR, coin->symbol, j == 0 ? "" : "old", (iter == 0) ? "peers" : "hdrs"), OS_compatible_path(fname);
#else
sprintf(fname,"%s/%s_%s%s.txt",GLOBAL_CONFSDIR,coin->symbol,j==0?"":"old",(iter == 0) ? "peers" : "hdrs"), OS_compatible_path(fname); sprintf(fname,"%s/%s_%s%s.txt",GLOBAL_CONFSDIR,coin->symbol,j==0?"":"old",(iter == 0) ? "peers" : "hdrs"), OS_compatible_path(fname);
#endif
//sprintf(fname,"confs/%s_%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs"); //sprintf(fname,"confs/%s_%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
//sprintf(fname,"tmp/%s/%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs"); //sprintf(fname,"tmp/%s/%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
OS_compatible_path(fname); OS_compatible_path(fname);

64
iguana/iguana_peers.c

@ -13,6 +13,19 @@
* * * *
******************************************************************************/ ******************************************************************************/
/**
* - we need to include WinSock2.h header to correctly use windows structure
* as the application is still using 32bit structure from mingw so, we need to
* add the include based on checking
* @author - fadedreamz@gmail.com
* @remarks - #if (defined(_M_X64) || defined(__amd64__)) && defined(WIN32)
* is equivalent to #if defined(_M_X64) as _M_X64 is defined for MSVC only
*/
#if defined(_M_X64)
#define WIN32_LEAN_AND_MEAN
#include <WinSock2.h>
#endif
#include "iguana777.h" #include "iguana777.h"
#define _iguana_hashfind(coin,ipbits) _iguana_hashset(coin,ipbits,-1) #define _iguana_hashfind(coin,ipbits) _iguana_hashset(coin,ipbits,-1)
@ -357,20 +370,70 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
struct sockaddr_in saddr; socklen_t addrlen,slen; struct sockaddr_in saddr; socklen_t addrlen,slen;
addrlen = sizeof(saddr); addrlen = sizeof(saddr);
struct hostent *hostent; struct hostent *hostent;
/**
* gethostbyname() is deprecated and cause crash on x64 windows
* the solution is to implement similar functionality by using getaddrinfo()
* it is standard posix function and is correctly supported in win32/win64/linux
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
struct addrinfo *addrresult = NULL;
struct addrinfo *returnptr = NULL;
struct addrinfo hints;
struct sockaddr_in * sockaddr_ipv4;
int retVal;
int found = 0;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
#endif
if ( parse_ipaddr(ipaddr,hostname) != 0 ) if ( parse_ipaddr(ipaddr,hostname) != 0 )
port = parse_ipaddr(ipaddr,hostname); port = parse_ipaddr(ipaddr,hostname);
#if defined(_M_X64)
retVal = getaddrinfo(ipaddr, NULL, &hints, &addrresult);
for (returnptr = addrresult; returnptr != NULL && found == 0; returnptr = returnptr->ai_next) {
switch (returnptr->ai_family) {
case AF_INET:
sockaddr_ipv4 = (struct sockaddr_in *) returnptr->ai_addr;
// we want to break from the loop after founding the first ipv4 address
found = 1;
break;
}
}
// if we iterate through the loop and didn't find anything,
// that means we failed in the dns lookup
if (found == 0) {
printf("getaddrinfo(%s) returned error\n", hostname);
freeaddrinfo(addrresult);
return(-1);
}
#else
hostent = gethostbyname(ipaddr); hostent = gethostbyname(ipaddr);
if ( hostent == NULL ) if ( hostent == NULL )
{ {
printf("gethostbyname(%s) returned error: %d port.%d ipaddr.(%s)\n",hostname,errno,port,ipaddr); printf("gethostbyname(%s) returned error: %d port.%d ipaddr.(%s)\n",hostname,errno,port,ipaddr);
return(-1); return(-1);
} }
#endif
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
saddr.sin_port = htons(port); saddr.sin_port = htons(port);
//#ifdef WIN32 //#ifdef WIN32
// saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1"); // saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1");
//#else //#else
#if defined(_M_X64)
saddr.sin_addr.s_addr = sockaddr_ipv4->sin_addr.s_addr;
// graceful cleanup
sockaddr_ipv4 = NULL;
freeaddrinfo(addrresult);
#else
memcpy(&saddr.sin_addr.s_addr,hostent->h_addr_list[0],hostent->h_length); memcpy(&saddr.sin_addr.s_addr,hostent->h_addr_list[0],hostent->h_length);
#endif
expand_ipbits(checkipaddr,saddr.sin_addr.s_addr); expand_ipbits(checkipaddr,saddr.sin_addr.s_addr);
if ( strcmp(ipaddr,checkipaddr) != 0 ) if ( strcmp(ipaddr,checkipaddr) != 0 )
printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)?\n",bindflag,checkipaddr,ipaddr); printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)?\n",bindflag,checkipaddr,ipaddr);
@ -1242,6 +1305,7 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
memset(&fds,0,sizeof(fds)); memset(&fds,0,sizeof(fds));
fds.fd = addr->usock; fds.fd = addr->usock;
fds.events |= (POLLOUT | POLLIN); fds.events |= (POLLOUT | POLLIN);
if ( poll(&fds,1,timeout) > 0 && (fds.revents & POLLOUT) != 0 ) if ( poll(&fds,1,timeout) > 0 && (fds.revents & POLLOUT) != 0 )
{ {
flag += iguana_pollsendQ(coin,addr); flag += iguana_pollsendQ(coin,addr);

29
iguana/iguana_ramchain.c

@ -1326,7 +1326,16 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
sprintf(fname,"%s/%s%s/spends/%s.%d",GLOBAL_DBDIR,iter==0?"ro/":"",coin->symbol,bits256_str(str,bp->hashes[0]),bp->bundleheight); sprintf(fname,"%s/%s%s/spends/%s.%d",GLOBAL_DBDIR,iter==0?"ro/":"",coin->symbol,bits256_str(str,bp->hashes[0]),bp->bundleheight);
if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 ) if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 )
{ {
#if defined(_M_X64)
/*
* calculate the address in a portable manner
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
ramchain->Xspendinds = (void *)((unsigned char *)ptr + sizeof(sha256));
#else
ramchain->Xspendinds = (void *)((long)ptr + sizeof(sha256)); ramchain->Xspendinds = (void *)((long)ptr + sizeof(sha256));
#endif
if ( bp->Xvalid == 0 ) if ( bp->Xvalid == 0 )
vcalc_sha256(0,sha256.bytes,(void *)ramchain->Xspendinds,(int32_t)(filesize - sizeof(sha256))); vcalc_sha256(0,sha256.bytes,(void *)ramchain->Xspendinds,(int32_t)(filesize - sizeof(sha256)));
ramchain->from_roX = (iter == 0); ramchain->from_roX = (iter == 0);
@ -1399,7 +1408,17 @@ struct iguana_ramchain *_iguana_ramchain_map(struct supernet_info *myinfo,struct
if ( ramchain->fileptr != 0 && ramchain->filesize > 0 ) if ( ramchain->fileptr != 0 && ramchain->filesize > 0 )
{ {
// verify hashes // verify hashes
/*
* calculate the address in a portable manner
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
ramchain->H.data = rdata = (void *)((unsigned char *)ramchain->fileptr + fpos);
#else
ramchain->H.data = rdata = (void *)(long)((long)ramchain->fileptr + fpos); ramchain->H.data = rdata = (void *)(long)((long)ramchain->fileptr + fpos);
#endif
ramchain->H.ROflag = 1; ramchain->H.ROflag = 1;
ramchain->expanded = expanded; ramchain->expanded = expanded;
ramchain->numblocks = (bp == 0) ? 1 : bp->n; ramchain->numblocks = (bp == 0) ? 1 : bp->n;
@ -2421,7 +2440,17 @@ int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_r
memset(mapchain,0,sizeof(*mapchain)); memset(mapchain,0,sizeof(*mapchain));
mapchain->fileptr = ptr; mapchain->fileptr = ptr;
mapchain->filesize = filesize; mapchain->filesize = filesize;
/*
* calculate the address in a portable manner
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
mapchain->H.data = (void *)((unsigned char *)ptr + block->fpos);
#else
mapchain->H.data = (void *)(long)((long)ptr + block->fpos); mapchain->H.data = (void *)(long)((long)ptr + block->fpos);
#endif
mapchain->H.ROflag = 1; mapchain->H.ROflag = 1;
if ( ptr == 0 || block->fpos > filesize ) if ( ptr == 0 || block->fpos > filesize )
{ {

34
iguana/iguana_tx.c

@ -15,14 +15,28 @@
#include "iguana777.h" #include "iguana777.h"
#if defined(_M_X64)
/*
* because we have no choice but to pass the value as parameters
* we need 64bit to hold 64bit memory address, thus changing
* to uint64_t instead of long in win x64
* @author - fadedreamz@gmail.com
*/
int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,uint64_t fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen)
#else
int32_t iguana_scriptdata(struct iguana_info *coin, uint8_t *scriptspace, long fileptr[2], char *fname, uint64_t scriptpos, int32_t scriptlen) int32_t iguana_scriptdata(struct iguana_info *coin, uint8_t *scriptspace, long fileptr[2], char *fname, uint64_t scriptpos, int32_t scriptlen)
#endif
{ {
FILE *fp; long err; int32_t retval = scriptlen; FILE *fp; long err; int32_t retval = scriptlen;
#ifndef __PNACL__ #ifndef __PNACL__
if ( scriptpos < 0xffffffff ) if ( scriptpos < 0xffffffff )
{ {
if ( fileptr[0] == 0 ) if ( fileptr[0] == 0 )
#if defined(_M_X64)
fileptr[0] = (uint64_t)OS_mapfile(fname,&fileptr[1],0);
#else
fileptr[0] = (long)OS_mapfile(fname, &fileptr[1], 0); fileptr[0] = (long)OS_mapfile(fname, &fileptr[1], 0);
#endif
if ( fileptr[0] != 0 ) if ( fileptr[0] != 0 )
{ {
if ( (scriptpos + scriptlen) <= fileptr[1] ) if ( (scriptpos + scriptlen) <= fileptr[1] )
@ -249,7 +263,17 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs) int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs)
{ {
#if defined(_M_X64)
/*
* because we have no choice but to access the memory address
* we need 64bit to correctly hold 64bit memory address, thus changing
* to uint64_t instead of long in win x64
* @author - fadedreamz@gmail.com
*/
struct iguana_txid *tx, T; bits256 checktxid; int32_t i, len, total, bundlei = -2; struct iguana_block *block; struct iguana_msgzblock zmsgB; bits256 *tree, checkhash2, merkle_root; struct iguana_bundle *bp = 0; uint64_t tmp; char str[65]; struct iguana_ramchaindata *rdata;
#else
struct iguana_txid *tx,T; bits256 checktxid; int32_t i,len,total,bundlei=-2; struct iguana_block *block; struct iguana_msgzblock zmsgB; bits256 *tree,checkhash2,merkle_root; struct iguana_bundle *bp=0; long tmp; char str[65]; struct iguana_ramchaindata *rdata; struct iguana_txid *tx,T; bits256 checktxid; int32_t i,len,total,bundlei=-2; struct iguana_block *block; struct iguana_msgzblock zmsgB; bits256 *tree,checkhash2,merkle_root; struct iguana_bundle *bp=0; long tmp; char str[65]; struct iguana_ramchaindata *rdata;
#endif
if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei >= 0 && bundlei < bp->n ) if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei >= 0 && bundlei < bp->n )
{ {
if ( (rdata= bp->ramchain.H.data) == 0 )//&& bp == coin->current ) if ( (rdata= bp->ramchain.H.data) == 0 )//&& bp == coin->current )
@ -298,7 +322,17 @@ int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info
} }
if ( i == block->RO.txn_count ) if ( i == block->RO.txn_count )
{ {
#if defined(_M_X64)
/*
* because we have no choice but to access the memory address
* we need 64bit to correctly hold 64bit memory address, thus changing
* to uint64_t instead of long in win x64
* @author - fadedreamz@gmail.com
*/
tmp = (uint64_t)&blockspace[sizeof(struct iguana_msghdr) + total + sizeof(bits256)];
#else
tmp = (long)&blockspace[sizeof(struct iguana_msghdr) + total + sizeof(bits256)]; tmp = (long)&blockspace[sizeof(struct iguana_msghdr) + total + sizeof(bits256)];
#endif
tmp &= ~(sizeof(bits256) - 1); tmp &= ~(sizeof(bits256) - 1);
tree = (void *)tmp; tree = (void *)tmp;
for (i=0; i<block->RO.txn_count; i++) for (i=0; i<block->RO.txn_count; i++)

10
iguana/iguana_txidfind.c

@ -193,7 +193,17 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl
// ramchain->sparsemax = i; // ramchain->sparsemax = i;
return(setind); return(setind);
} }
// fadedreamz@gmail.com
#if defined(_M_X64)
/*
* calculate the address in a portable manner
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
else if (x < maxitems && memcmp((void *)((unsigned char *)refdata + x*refsize), key, keylen) == 0)
#else
else if ( x < maxitems && memcmp((void *)(long)((long)refdata + x*refsize),key,keylen) == 0 ) else if ( x < maxitems && memcmp((void *)(long)((long)refdata + x*refsize),key,keylen) == 0 )
#endif
{ {
if ( setind == 0 ) if ( setind == 0 )
ramchain->sparsehits++; ramchain->sparsehits++;

1
includes/iguana_defines.h

@ -58,6 +58,7 @@
#define IGUANA_MAXBUNDLES (50000000 / 500) #define IGUANA_MAXBUNDLES (50000000 / 500)
#define IGUANA_MINPEERS 64 #define IGUANA_MINPEERS 64
#define IGUANA_LOG2MAXPEERS 11 // cant exceed 13 bits as ramchain unspents has bitfield #define IGUANA_LOG2MAXPEERS 11 // cant exceed 13 bits as ramchain unspents has bitfield
#define IGUANA_MAXPEERS (1 << IGUANA_LOG2MAXPEERS) #define IGUANA_MAXPEERS (1 << IGUANA_LOG2MAXPEERS)

9
includes/iguana_funcs.h

@ -580,7 +580,16 @@ struct iguana_peer *iguana_peerfindipbits(struct iguana_info *coin,uint32_t ipbi
//int32_t basilisk_relays_send(struct supernet_info *myinfo,struct iguana_peer *addr); //int32_t basilisk_relays_send(struct supernet_info *myinfo,struct iguana_peer *addr);
int32_t basilisk_hashes_send(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_peer *addr,char *CMD,bits256 *txids,int32_t num); int32_t basilisk_hashes_send(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_peer *addr,char *CMD,bits256 *txids,int32_t num);
int32_t iguana_opreturn(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int64_t crypto777_payment,int32_t height,uint64_t hdrsi_unspentind,int64_t payment,uint32_t fileid,uint64_t scriptpos,uint32_t scriptlen); int32_t iguana_opreturn(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int64_t crypto777_payment,int32_t height,uint64_t hdrsi_unspentind,int64_t payment,uint32_t fileid,uint64_t scriptpos,uint32_t scriptlen);
/*
* because the address passed in a non-portable way we defined uint64_t as parameter to
* allow the pass of 64bit memory address in windows 64
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
int32_t iguana_scriptdata(struct iguana_info *coin, uint8_t *scriptspace, uint64_t fileptr[2], char *fname, uint64_t scriptpos, int32_t scriptlen);
#else
int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen); int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen);
#endif
void basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *notaries,uint32_t ipbits); void basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *notaries,uint32_t ipbits);
void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr); void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr);
int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]); int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]);

20
includes/iguana_structs.h

@ -301,7 +301,17 @@ struct iguana_txblock
struct iguana_zblock zblock; struct iguana_zblock zblock;
}; };
#if defined(_M_X64)
/*
* calculate the address in a portable manner
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
#define RAMCHAIN_PTR(rdata,offset) ((void *)((unsigned char *)rdata + rdata->offset))
#else
#define RAMCHAIN_PTR(rdata,offset) ((void *)(long)((long)(rdata) + (long)(rdata)->offset)) #define RAMCHAIN_PTR(rdata,offset) ((void *)(long)((long)(rdata) + (long)(rdata)->offset))
#endif
struct iguana_ramchaindata struct iguana_ramchaindata
{ {
bits256 sha256; bits256 sha256;
@ -461,7 +471,17 @@ struct iguana_info
struct iguana_peers *peers; struct iguana_peer internaladdr; struct iguana_peers *peers; struct iguana_peer internaladdr;
//basilisk_func basilisk_rawtx,basilisk_balances,basilisk_value; //basilisk_func basilisk_rawtx,basilisk_balances,basilisk_value;
//basilisk_metricfunc basilisk_rawtxmetric,basilisk_balancesmetric,basilisk_valuemetric; //basilisk_metricfunc basilisk_rawtxmetric,basilisk_balancesmetric,basilisk_valuemetric;
#if defined(_M_X64)
/*
* because we have no choice but to pass the value as parameters
* we need 64bit to hold 64bit memory address, thus changing
* to uint64_t instead of long in win x64
* @author - fadedreamz@gmail.com
*/
uint64_t vinptrs[IGUANA_MAXPEERS + 1][2], voutptrs[IGUANA_MAXPEERS + 1][2];
#else
long vinptrs[IGUANA_MAXPEERS+1][2],voutptrs[IGUANA_MAXPEERS+1][2]; long vinptrs[IGUANA_MAXPEERS+1][2],voutptrs[IGUANA_MAXPEERS+1][2];
#endif
uint32_t fastfind; FILE *fastfps[0x100]; uint8_t *fast[0x100]; int32_t *fasttables[0x100]; long fastsizes[0x100]; uint32_t fastfind; FILE *fastfps[0x100]; uint8_t *fast[0x100]; int32_t *fasttables[0x100]; long fastsizes[0x100];
uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime; uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime;
int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,PREFETCHLAG,estsize,activebundles; int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,PREFETCHLAG,estsize,activebundles;

Loading…
Cancel
Save