Browse Source

Merge pull request #196 from jl777/dev

Dev
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
0deeeee270
  1. 1
      basilisk/basilisk_MSG.c
  2. 12
      basilisk/basilisk_swap.c
  3. 6
      basilisk/tradebots_liquidity.c
  4. 2
      iguana/dPoW.h
  5. 62
      iguana/dpow/dpow_network.c
  6. 13
      iguana/iguana_secp.c
  7. 3
      iguana/tests/requestM

1
basilisk/basilisk_MSG.c

@ -217,6 +217,7 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3
HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg);
QUEUEITEMS++;
portable_mutex_unlock(&myinfo->messagemutex);
printf("add message keylen.%d [%d]\n",msg->keylen,datalen);
//if ( myinfo->NOTARY.RELAYID >= 0 )
// dpow_handler(myinfo,msg);
if ( sendping != 0 )

12
basilisk/basilisk_swap.c

@ -1022,15 +1022,18 @@ void basilisk_rawtx_setparms(char *name,struct supernet_info *myinfo,struct basi
int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobcoinp,struct iguana_info **alicecoinp,char *src,char *dest,bits256 srchash,bits256 desthash)
{
struct iguana_info *coin = iguana_coinfind(src);
if ( coin == 0 || iguana_coinfind(dest) == 0 )
return(0);
*bobcoinp = *alicecoinp = 0;
if ( strcmp("BTC",src) == 0 )
if ( strcmp("BTC",src) == 0 || coin->notarychain >= 0 )
{
*bobcoinp = iguana_coinfind("BTC");
*bobcoinp = iguana_coinfind(src);
*alicecoinp = iguana_coinfind(dest);
}
else if ( strcmp("BTC",dest) == 0 )
else //if ( strcmp("BTC",dest) == 0 )
{
*bobcoinp = iguana_coinfind("BTC");
*bobcoinp = iguana_coinfind(dest);
*alicecoinp = iguana_coinfind(src);
}
if ( bits256_cmp(myinfo->myaddr.persistent,srchash) == 0 )
@ -1862,6 +1865,7 @@ void basilisk_swaploop(void *_swap)
struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration)
{
int32_t i,m,n; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; struct basilisk_swap *swap = 0;
printf("basilisk_thread_start\n");
portable_mutex_lock(&myinfo->DEX_swapmutex);
for (i=0; i<myinfo->numswaps; i++)
if ( myinfo->swaps[i]->I.req.requestid == rp->requestid )

6
basilisk/tradebots_liquidity.c

@ -1000,7 +1000,7 @@ double _default_liquidity_active(struct supernet_info *myinfo,double *refpricep,
{
int32_t i,dir; struct liquidity_info refli;
*refpricep = 0.;
//printf("%s %s/%s\n",exchange,base,rel);
printf("_default_liquidity_active %s %s/%s\n",exchange,base,rel);
for (i=0; i<sizeof(myinfo->linfos)/sizeof(*myinfo->linfos); i++)
{
refli = myinfo->linfos[i];
@ -1013,10 +1013,10 @@ double _default_liquidity_active(struct supernet_info *myinfo,double *refpricep,
else dir = 0;
if ( exchange[0] != 0 && refli.exchange[0] != 0 && strcmp(exchange,refli.exchange) != 0 )
{
//printf("continue %s %s/%s [%d] dir.%d refli.dir %d vs %s %s/%s\n",exchange,base,rel,i,dir,refli.dir,refli.exchange,refli.base,refli.rel);
printf("continue %s %s/%s [%d] dir.%d vs %s %s/%s\n",exchange,base,rel,i,dir,refli.exchange,refli.base,refli.rel);
continue;
}
//printf(">>>>>>>> %s %s/%s [%d] dir.%d refli.dir %d vs %s/%s\n",exchange,base,rel,i,dir,refli.dir,refli.base,refli.rel);
printf(">>>>>>>> %s %s/%s [%d] dir.%d vs %s/%s\n",exchange,base,rel,i,dir,refli.base,refli.rel);
if ( _default_volume_ok(myinfo,&refli,dir,volume) == 0 )
{
if ( refli.profit != 0. )

2
iguana/dPoW.h

@ -22,7 +22,7 @@
#define DPOW_MINSIGS 17
//#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1)
#define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries)
#define DPOW_VERSION 0x0779
#define DPOW_VERSION 0x0780
#define DPOW_UTXOSIZE 10000
#define DPOW_MINOUTPUT 6000
#define DPOW_DURATION 600

62
iguana/dpow/dpow_network.c

@ -23,7 +23,7 @@ struct signed_nnpacket
int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32_t size)
{
int32_t i,sentbytes,siglen = 0; uint8_t sig[65],pubkey33[33]; struct signed_nnpacket *sigpacket;
int32_t i,j,sentbytes,siglen = 0; uint8_t sig[65],pubkey33[33],signpubkey33[33]; struct signed_nnpacket *sigpacket;
if ( (sigpacket= calloc(1,size + sizeof(*sigpacket))) != 0 )
{
sigpacket->packetlen = size;
@ -35,17 +35,31 @@ int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32
if ( sigpacket->packethash.bytes[0] == 0 )
break;
}
bitcoin_pubkey33(ctx,pubkey33,privkey);
if ( i < 10000 && (siglen= bitcoin_sign(ctx,"nnsend",sig,sigpacket->packethash,privkey,1)) > 0 && siglen == 65 )
bitcoin_pubkey33(ctx,signpubkey33,privkey);
for (j=0; j<10; j++)
{
//for (i=0; i<33; i++)
// printf("%02x",pubkey33[i]);
//printf(" signed pubkey\n");
memcpy(sigpacket->sig64,sig+1,64);
sentbytes = nn_send(sock,sigpacket,size + sizeof(*sigpacket),0);
return(sentbytes - siglen);
} else printf("couldnt find nonce\n");
if ( i < 10000 && (siglen= bitcoin_sign(ctx,"nnsend",sig,sigpacket->packethash,privkey,1)) > 0 && siglen == 65 )
{
memcpy(sigpacket->sig64,sig+1,64);
if ( bitcoin_recoververify(ctx,"nnrecv",sigpacket->sig64,sigpacket->packethash,pubkey33,33) == 0 )
{
//for (i=0; i<33; i++)
// printf("%02x",pubkey33[i]);
//printf(" signed pubkey\n");
if ( memcmp(pubkey33,signpubkey33,33) == 0 )
{
sentbytes = nn_send(sock,sigpacket,size + sizeof(*sigpacket),0);
//for (i=0; i<size+sizeof(*sigpacket); i++)
// printf("%02x",((uint8_t *)sigpacket)[i]);
//printf(" <- nnsend\n");
free(sigpacket);
return(sentbytes - siglen);
}
}
}
}
free(sigpacket);
printf("error signing nnpacket\n");
}
return(-1);
}
@ -55,7 +69,12 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_
int32_t i,recvbytes; uint8_t pubkey33[33],pubkey0[33]; bits256 packethash; struct signed_nnpacket *sigpacket=0;
*(void **)packetp = 0;
*freeptrp = 0;
recvbytes = nn_recv(sock,&sigpacket,NN_MSG,0);
if ( (recvbytes= nn_recv(sock,&sigpacket,NN_MSG,0)) > 0 )
{
//for (i=0; i<recvbytes; i++)
// printf("%02x",((uint8_t *)sigpacket)[i]);
//printf(" <- RECV.%d\n",recvbytes);
}
if ( sigpacket != 0 && recvbytes > sizeof(*sigpacket) && sigpacket->packetlen == recvbytes-sizeof(*sigpacket) )
{
vcalc_sha256(0,packethash.bytes,(void *)&sigpacket->nonce,(int32_t)(sigpacket->packetlen+sizeof(sigpacket->nonce)+sizeof(sigpacket->packetlen)));
@ -90,9 +109,9 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_
printf(" pubkey[%d]\n",i);
}
}
//for (i=0; i<33; i++)
// printf("%02x",pubkey33[i]);
//printf(" invalid pubkey33 n.%d\n",n);
for (i=0; i<33; i++)
printf("%02x",pubkey33[i]);
printf(" invalid pubkey33 n.%d\n",n);
} else printf("recoververify error nonce.%u packetlen.%d\n",sigpacket->nonce,sigpacket->packetlen);
} else printf("hash mismatch or bad nonce.%u packetlen.%d\n",sigpacket->nonce,sigpacket->packetlen);
} //else printf("recvbytes.%d mismatched packetlen.%d + %ld\n",recvbytes,sigpacket!=0?sigpacket->packetlen:-1,sizeof(*sigpacket));
@ -169,8 +188,8 @@ void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t
char *retstr; int32_t datalen; struct iguana_info *coin; struct dex_request dexreq;
//for (i=0; i<size; i++)
// printf("%02x",((uint8_t *)dexp)[i]);
printf(" uniq DEX_PACKET.[%d] crc.%x lag.%d (%d %d)\n",size,calc_crc32(0,dexp->packet,dexp->datalen),(int32_t)(time(NULL)-dexp->timestamp),dexp->size,dexp->datalen);
if ( strcmp(dexp->handler,"DEX") == 0 )//dexp->datalen > BASILISK_KEYSIZE )
printf(" uniq.%s DEX_PACKET.[%d] crc.%x lag.%d (%d %d)\n",dexp->handler,size,calc_crc32(0,dexp->packet,dexp->datalen),(int32_t)(time(NULL)-dexp->timestamp),dexp->size,dexp->datalen);
if ( strcmp(dexp->handler,"DEX") == 0 && dexp->datalen > BASILISK_KEYSIZE )
{
if ( (retstr= basilisk_respond_addmessage(myinfo,dexp->packet,BASILISK_KEYSIZE,&dexp->packet[BASILISK_KEYSIZE],dexp->datalen-BASILISK_KEYSIZE,0,BASILISK_DEXDURATION)) != 0 )
free(retstr);
@ -204,7 +223,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
{
timeout = 100;
nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
timeout = 1000;
timeout = 3000;
nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
//nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout));
if ( myinfo->IAMNOTARY == 0 && subsock < 0 && (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 )
@ -264,7 +283,10 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
portable_mutex_lock(&myinfo->dexmutex);
ipbits = 0;
if ( strcmp(handler,"DEX") == 0 )
ipbits = *retptr;
{
if ( retptr != 0 )
ipbits = *retptr;
}
else if ( retptr != 0 )
{
retstr = clonestr((char *)retptr);
@ -296,7 +318,8 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str);
}
}
//nn_connect(myinfo->reqsock,nanomsg_tcpname(0,str,ipaddr,REP_SOCK));
nanomsg_tcpname(0,str,ipaddr,REP_SOCK);
//nn_connect(myinfo->reqsock,str);
printf("%d: req connect (%s)\n",myinfo->numdexipbits,str);
}
}
@ -1638,7 +1661,6 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 )
{
num++;
//fprintf(stderr,"%d ",size);
//printf("REP got %d\n",size);
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 )
{

13
iguana/iguana_secp.c

@ -131,8 +131,13 @@ int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256
{
sig[0] = 27 + recid + (fCompressed != 0 ? 4 : 0);
retval = 64 + 1;
}
else printf("secpub mismatch\n");
//size_t i,plen = 33; uint8_t pubkey[33];
//secp256k1_ec_pubkey_serialize(ctx,pubkey,&plen,&CHECKPUB,SECP256K1_EC_COMPRESSED);
//for (i=0; i<33; i++)
// printf("%02x",pubkey[i]);
//printf(" bitcoin_sign's pubkey\n");
} else printf("secpub mismatch\n");
} else printf("pubkey create error\n");
} else printf("recover error\n");
} else printf("secp256k1_ecdsa_sign_recoverable error\n");
@ -167,6 +172,7 @@ int32_t bitcoin_recoververify(void *ctx,char *symbol,uint8_t *sig,bits256 messag
if ( secp256k1_ecdsa_recover(ctx,&PUB,&rSIG,messagehash2.bytes) != 0 )
{
plen = 33;
memset(pubkey,0,33);
secp256k1_ec_pubkey_serialize(ctx,pubkey,&plen,&PUB,SECP256K1_EC_COMPRESSED);//plen == 65 ? SECP256K1_EC_UNCOMPRESSED : SECP256K1_EC_COMPRESSED);
if ( secp256k1_ecdsa_verify(ctx,&SIG,messagehash2.bytes,&PUB) != 0 )
{
@ -175,8 +181,7 @@ int32_t bitcoin_recoververify(void *ctx,char *symbol,uint8_t *sig,bits256 messag
pubkey[0] = 2;
else if ( pubkey[0] != 2 )
pubkey[0] = 3;*/
}
else printf("secp256k1_ecdsa_verify error\n");
} else printf("secp256k1_ecdsa_verify error\n");
} else printf("secp256k1_ecdsa_recover error\n");
ENDSECP_ENSURE_CTX
}

3
iguana/tests/requestM

@ -0,0 +1,3 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"MVP\",\"amount\":0.1,\"dest\":\"USD\",\"minprice\":0.09}}"
Loading…
Cancel
Save