From ee03fa567e14dccd8106b11b44a118e322c3807a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Oct 2017 23:29:26 +0300 Subject: [PATCH 01/63] Test --- crypto777/nanosrc/aio/usock_posix.c | 76 ++++++++++----------- crypto777/nanosrc/core/global.c | 4 +- crypto777/nanosrc/core/sock.c | 4 +- crypto777/nanosrc/nn_config.h | 4 +- crypto777/nanosrc/transports/utils/tcpmux.c | 2 +- crypto777/nanosrc/transports/ws/sws.c | 2 +- 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/crypto777/nanosrc/aio/usock_posix.c b/crypto777/nanosrc/aio/usock_posix.c index 3989d3a22..2f85e559c 100755 --- a/crypto777/nanosrc/aio/usock_posix.c +++ b/crypto777/nanosrc/aio/usock_posix.c @@ -167,7 +167,7 @@ int nn_usock_start (struct nn_usock *self, int domain, int type, int protocol) s = socket (domain, type, protocol); if (nn_slow (s < 0)) return -errno; - //PNACL_msg("got socket s.%d\n",s); + //printf("got socket s.%d\n",s); nn_usock_init_from_fd (self, s); /* Start the state machine. */ @@ -286,14 +286,14 @@ int nn_usock_bind (struct nn_usock *self, const struct sockaddr *addr, /* Allow re-using the address. */ opt = 1; - PNACL_msg("call setsockopt %d SOL_SOCKET.%d SO_REUSEADDR.%d in nn_usock_bind\n",self->s,SOL_SOCKET,SO_REUSEADDR); + printf("call setsockopt %d SOL_SOCKET.%d SO_REUSEADDR.%d in nn_usock_bind\n",self->s,SOL_SOCKET,SO_REUSEADDR); rc = setsockopt (self->s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt)); - PNACL_msg("called setsockopt in nn_usock_bind returns %d\n",rc); + printf("called setsockopt in nn_usock_bind returns %d\n",rc); // ignore SO_REUSEADDR failures //errno_assert (rc == 0); rc = bind (self->s, addr, (socklen_t) addrlen); - PNACL_msg("usock.%d -> bind rc.%d errno.%d %s\n",self->s,rc,errno,nn_strerror(errno)); + printf("usock.%d -> bind rc.%d errno.%d %s\n",self->s,rc,errno,nn_strerror(errno)); if (nn_slow (rc != 0)) return -errno; @@ -309,7 +309,7 @@ int nn_usock_listen (struct nn_usock *self, int backlog) /* Start listening for incoming connections. */ rc = listen (self->s, backlog); - //PNACL_msg("usock.%d -> listen rc.%d errno.%d %s\n",self->s,rc,errno,nn_strerror(errno)); + printf("usock.%d -> listen rc.%d errno.%d %s\n",self->s,rc,errno,nn_strerror(errno)); if (nn_slow (rc != 0)) return -errno; @@ -336,7 +336,7 @@ void nn_usock_accept (struct nn_usock *self, struct nn_usock *listener) #else s = accept (listener->s, NULL, NULL); #endif - //PNACL_msg("usock.%d -> accept errno.%d s.%d %s\n",self->s,errno,s,nn_strerror(errno)); + printf("usock.%d -> accept errno.%d s.%d %s\n",self->s,errno,s,nn_strerror(errno)); /* Immediate success. */ if (nn_fast (s >= 0)) { @@ -369,7 +369,7 @@ void nn_usock_accept (struct nn_usock *self, struct nn_usock *listener) and allow processing other events in the meantime */ if (nn_slow (errno != EAGAIN && errno != EWOULDBLOCK && errno != ECONNABORTED && errno != listener->errnum)) { - PNACL_msg("listen errno.%d\n",errno); + printf("listen errno.%d\n",errno); listener->errnum = errno; listener->state = NN_USOCK_STATE_ACCEPTING_ERROR; nn_fsm_raise (&listener->fsm, @@ -396,7 +396,7 @@ void nn_usock_connect (struct nn_usock *self, const struct sockaddr *addr, /* Do the connect itself. */ rc = connect(self->s,addr,(socklen_t)addrlen); - //PNACL_msg("usock.%d <- connect (%llx) rc.%d errno.%d %s\n",self->s,*(long long *)addr,rc,errno,nn_strerror(errno)); + printf("usock.%d <- connect (%llx) rc.%d errno.%d %s\n",self->s,*(long long *)addr,rc,errno,nn_strerror(errno)); /* Immediate success. */ if ( nn_fast(rc == 0) ) { @@ -407,7 +407,7 @@ void nn_usock_connect (struct nn_usock *self, const struct sockaddr *addr, if ( nn_slow(errno != EINPROGRESS) ) { self->errnum = errno; - PNACL_msg("error.%d not EINPROGRESS\n",errno); + printf("error.%d not EINPROGRESS\n",errno); nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); return; } @@ -436,13 +436,13 @@ void nn_usock_send (struct nn_usock *self, const struct nn_iovec *iov, self->out.iov [out].iov_base = iov [i].iov_base; self->out.iov [out].iov_len = iov [i].iov_len; out++; - //PNACL_msg("{%d} ",(int)iov [i].iov_len); + printf("{%d} ",(int)iov [i].iov_len); } - //PNACL_msg("iov[%d]\n",out); self->out.hdr.msg_iovlen = out; /* Try to send the data immediately. */ rc = nn_usock_send_raw (self, &self->out.hdr); + printf("iov[%d] nn_usock_send_raw -> rc.%d\n",out,rc); /* Success. */ if (nn_fast (rc == 0)) { @@ -475,17 +475,17 @@ void nn_usock_recv (struct nn_usock *self, void *buf, size_t len, int *fd) rc = nn_usock_recv_raw (self, buf, &nbytes); if (nn_slow (rc < 0)) { errnum_assert (rc == -ECONNRESET, -rc); - //PNACL_msg("rc.%d vs ECONNRESET\n",rc,ECONNRESET); + //printf("rc.%d vs ECONNRESET\n",rc,ECONNRESET); nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); return; } //int i; //for (i=0; i<16&&ifsm, &self->event_received, NN_USOCK_RECEIVED); return; } @@ -1024,19 +1024,19 @@ int32_t nn_getiovec_size(uint8_t *buf,int32_t maxlen,struct msghdr *hdr) if ( nn_slow(iov->iov_len == NN_MSG) ) { errno = EINVAL; - PNACL_msg("ERROR: iov->iov_len == NN_MSG\n"); + printf("ERROR: iov->iov_len == NN_MSG\n"); return(-1); } if ( nn_slow(!iov->iov_base && iov->iov_len) ) { errno = EFAULT; - PNACL_msg("ERROR: !iov->iov_base && iov->iov_len\n"); + printf("ERROR: !iov->iov_base && iov->iov_len\n"); return(-1); } if ( maxlen > 0 && nn_slow(size + iov->iov_len > maxlen) ) { errno = EINVAL; - PNACL_msg("ERROR: sz.%d + iov->iov_len.%d < maxlen.%d\n",(int32_t)size,(int32_t)iov->iov_len,maxlen); + printf("ERROR: sz.%d + iov->iov_len.%d < maxlen.%d\n",(int32_t)size,(int32_t)iov->iov_len,maxlen); return(-1); } if ( iov->iov_len > 0 ) @@ -1057,7 +1057,7 @@ ssize_t mysendmsg(int32_t usock,struct msghdr *hdr,int32_t flags) clen = hdr->msg_controllen; if ( hdr->msg_control == 0 ) clen = 0; - nn_assert(clen == 0); // no supporty control messagies + nn_assert(clen == 0); // no support control messagies if ( veclen > sizeof(_buf) ) // - clen - 5) ) buf = malloc(veclen);// + clen + 5); else buf = _buf; @@ -1072,10 +1072,10 @@ ssize_t mysendmsg(int32_t usock,struct msghdr *hdr,int32_t flags) if ( nn_getiovec_size(&buf[offset],veclen,hdr) == veclen ) { nbytes = send(usock,buf,offset + veclen,0); - //PNACL_msg(">>>>>>>>> send.[%d %d %d %d] (n.%d v.%d c.%d)-> usock.%d nbytes.%d\n",buf[offset],buf[offset+1],buf[offset+2],buf[offset+3],(int32_t)offset+veclen,veclen,clen,usock,(int32_t)nbytes); + printf(">>>>>>>>> send.[%d %d %d %d] (n.%d v.%d c.%d)-> usock.%d nbytes.%d\n",buf[offset],buf[offset+1],buf[offset+2],buf[offset+3],(int32_t)offset+veclen,veclen,clen,usock,(int32_t)nbytes); if ( nbytes != offset + veclen ) { - //PNACL_msg("nbytes.%d != offset.%d veclen.%d errno.%d usock.%d\n",(int32_t)nbytes,(int32_t)offset,veclen,errno,usock); + printf("nbytes.%d != offset.%d veclen.%d errno.%d usock.%d\n",(int32_t)nbytes,(int32_t)offset,veclen,errno,usock); } if ( nbytes >= offset ) nbytes -= offset; @@ -1083,19 +1083,19 @@ ssize_t mysendmsg(int32_t usock,struct msghdr *hdr,int32_t flags) else { err = -errno; - PNACL_msg("mysendmsg: unexpected nn_getiovec_size error %d\n",err); + printf("mysendmsg: unexpected nn_getiovec_size error %d\n",err); } if ( buf != _buf ) free(buf); if ( err != 0 ) { - PNACL_msg("nn_usock_send_raw errno.%d err.%d\n",errno,err); + printf("nn_usock_send_raw errno.%d err.%d\n",errno,err); return(-errno); } } else { - PNACL_msg("nn_usock_send_raw errno.%d invalid iovec size\n",errno); + printf("nn_usock_send_raw errno.%d invalid iovec size\n",errno); return(-errno); } return(nbytes); @@ -1107,32 +1107,32 @@ ssize_t myrecvmsg(int32_t usock,struct msghdr *hdr,int32_t flags,int32_t len) iov = hdr->msg_iov; /*if ( (n= (int32_t)recv(usock,lens,sizeof(lens),0)) != sizeof(lens) ) { - PNACL_msg("error getting veclen/clen n.%d vs %d from usock.%d\n",n,(int32_t)sizeof(lens),usock); + printf("error getting veclen/clen n.%d vs %d from usock.%d\n",n,(int32_t)sizeof(lens),usock); return(0); - } else PNACL_msg("GOT %d bytes from usock.%d\n",n,usock); + } else printf("GOT %d bytes from usock.%d\n",n,usock); offset = 0; veclen = lens[offset++]; veclen |= ((int32_t)lens[offset++] << 8); veclen |= ((int32_t)lens[offset++] << 16); clen = lens[offset++]; clen |= ((int32_t)lens[offset++] << 8); - PNACL_msg("veclen.%d clen.%d waiting in usock.%d\n",veclen,clen,usock); + printf("veclen.%d clen.%d waiting in usock.%d\n",veclen,clen,usock); if ( clen > 0 ) { if ( (cbytes= (int32_t)recv(usock,hdr->msg_control,clen,0)) != clen ) { - PNACL_msg("myrecvmsg: unexpected cbytes.%d vs clen.%d\n",cbytes,clen); + printf("myrecvmsg: unexpected cbytes.%d vs clen.%d\n",cbytes,clen); } } else cbytes = 0;*/ hdr->msg_controllen = 0; if ( (nbytes= (int32_t)recv(usock,iov->iov_base,len,0)) != len ) { - //PNACL_msg("myrecvmsg: partial nbytes.%d vs veclen.%d\n",(int32_t)nbytes,len); + //printf("myrecvmsg: partial nbytes.%d vs veclen.%d\n",(int32_t)nbytes,len); } - //PNACL_msg("GOT nbytes.%d of len.%d from usock.%d\n",(int32_t)nbytes,len,usock); + //printf("GOT nbytes.%d of len.%d from usock.%d\n",(int32_t)nbytes,len,usock); if ( 0 && nbytes > 0 ) { - PNACL_msg("got nbytes.%d from usock.%d [%d %d %d %d]\n",(int32_t)nbytes,usock,((uint8_t *)iov->iov_base)[0],((uint8_t *)iov->iov_base)[1],((uint8_t *)iov->iov_base)[2],((uint8_t *)iov->iov_base)[3]); + printf("got nbytes.%d from usock.%d [%d %d %d %d]\n",(int32_t)nbytes,usock,((uint8_t *)iov->iov_base)[0],((uint8_t *)iov->iov_base)[1],((uint8_t *)iov->iov_base)[2],((uint8_t *)iov->iov_base)[3]); } return(nbytes); } @@ -1147,7 +1147,7 @@ static int nn_usock_send_raw (struct nn_usock *self, struct msghdr *hdr) nbytes = sendmsg(self->s,hdr,MSG_NOSIGNAL); #else nbytes = sendmsg(self->s,hdr,0); - //PNACL_msg("sendmsg nbytes.%d\n",(int32_t)nbytes); + printf("nn_usock_send_raw nbytes.%d\n",(int32_t)nbytes); #endif #endif /* Handle errors. */ @@ -1202,13 +1202,13 @@ int32_t nn_process_cmsg(struct nn_usock *self,struct msghdr *hdr) memcpy(&retval,(int32_t *)CMSG_DATA(cmsg),sizeof(int32_t)); if ( self->in.pfd ) { - PNACL_msg("CMSG set self->in.pfd (%d)\n",retval); + printf("CMSG set self->in.pfd (%d)\n",retval); *self->in.pfd = retval; self->in.pfd = NULL; } else { - PNACL_msg("CMSG nn_closefd(%d)\n",retval); + printf("CMSG nn_closefd(%d)\n",retval); nn_closefd(retval); } break; @@ -1260,7 +1260,7 @@ static int nn_usock_recv_raw(struct nn_usock *self, void *buf, size_t *len) if (!length) return 0; } -#ifdef NN_USE_MYMSG +#if NN_USE_MYMSG usebuf = (length >= NN_USOCK_BATCH_SIZE); #else usebuf = (length >= NN_USOCK_BATCH_SIZE); @@ -1289,7 +1289,7 @@ static int nn_usock_recv_raw(struct nn_usock *self, void *buf, size_t *len) #if NN_USE_MYMSG nbytes = myrecvmsg(self->s,&hdr,0,(int32_t)iov.iov_len); - //PNACL_msg("got nbytes.%d from recvmsg errno.%d %s\n",(int32_t)nbytes,errno,nn_strerror(errno)); + printf("got nbytes.%d from recvmsg errno.%d %s\n",(int32_t)nbytes,errno,nn_strerror(errno)); #else nbytes = recvmsg (self->s, &hdr, 0); #endif @@ -1301,7 +1301,7 @@ static int nn_usock_recv_raw(struct nn_usock *self, void *buf, size_t *len) nbytes = 0; else { - PNACL_msg("recvraw errno.%d %s\n",errno,nn_strerror(errno)); + printf("recvraw errno.%d %s\n",errno,nn_strerror(errno)); // If the peer closes the connection, return ECONNRESET errno_assert(errno == ECONNRESET || errno == ENOTCONN || errno == ECONNREFUSED || errno == ETIMEDOUT || errno == EHOSTUNREACH #if NN_USE_MYMSG @@ -1313,7 +1313,7 @@ static int nn_usock_recv_raw(struct nn_usock *self, void *buf, size_t *len) } } else if ( hdr.msg_controllen > 0 ) nn_process_cmsg(self,&hdr); - //PNACL_msg("nbytes.%d length.%d *len %d\n",(int)nbytes,(int)length,(int)*len); + printf("nbytes.%d length.%d *len %d\n",(int)nbytes,(int)length,(int)*len); // If the data were received directly into the place we can return straight away if ( usebuf != 0 ) diff --git a/crypto777/nanosrc/core/global.c b/crypto777/nanosrc/core/global.c index 3c6f07011..c654753fd 100755 --- a/crypto777/nanosrc/core/global.c +++ b/crypto777/nanosrc/core/global.c @@ -668,7 +668,7 @@ int32_t nn_recv(int32_t s,void *buf,size_t len,int32_t flags) return nn_recvmsg(s,&hdr,flags); } -#ifdef NN_USE_MYMSG +#if NN_USE_MYMSG int32_t nn_sendmsg(int32_t s,const struct nn_msghdr *msghdr,int32_t flags) { @@ -1253,7 +1253,7 @@ static int nn_global_create_ep (int s, const char *addr, int bind) return -EINVAL; protosz = delim - addr; addr += protosz + 3; -#ifdef NN_USE_MYMSG +#if NN_USE_MYMSG if ( strncmp("inproc",proto,strlen("inproc")) != 0 && strncmp("ipc",proto,strlen("ipc")) != 0 && strncmp("tcp",proto,strlen("tcp")) && strncmp("ws",proto,strlen("ws")) != 0 ) { PNACL_msg("only ipc, inproc, ws and tcp transport is supported\n"); diff --git a/crypto777/nanosrc/core/sock.c b/crypto777/nanosrc/core/sock.c index 83e8afce7..7427a5fc4 100755 --- a/crypto777/nanosrc/core/sock.c +++ b/crypto777/nanosrc/core/sock.c @@ -548,6 +548,7 @@ int nn_sock_send(struct nn_sock *self, struct nn_msg *msg, int flags) /* Try to send the message in a non-blocking way. */ rc = self->sockbase->vfptr->send (self->sockbase, msg); +printf("sockbase send rc.%d\n",rc); if (nn_fast (rc == 0)) { nn_ctx_leave (&self->ctx); return 0; @@ -560,8 +561,7 @@ int nn_sock_send(struct nn_sock *self, struct nn_msg *msg, int flags) return rc; } - /* If the message cannot be sent at the moment and the send call - is non-blocking, return immediately. */ + // If the message cannot be sent at the moment and the send call is non-blocking, return immediately. if (nn_fast (flags & NN_DONTWAIT)) { nn_ctx_leave (&self->ctx); return -EAGAIN; diff --git a/crypto777/nanosrc/nn_config.h b/crypto777/nanosrc/nn_config.h index 74edc6229..d98b64038 100755 --- a/crypto777/nanosrc/nn_config.h +++ b/crypto777/nanosrc/nn_config.h @@ -58,10 +58,10 @@ performance optimal make sure that this value is larger than network MTU. */ #define NN_USOCK_BATCH_SIZE (2048) //#define NN_USOCK_BATCH_SIZE (_NN_USOCK_BATCH_SIZE - 5 - 256 - 16) // adjust for veclen/clen + sizeof(ctrl) -#define NN_USE_MYMSG 1 +#define NN_USE_MYMSG 0 #if defined __PNACL || defined __APPLE__ -#define NN_USE_MYMSG 1 +#define NN_USE_MYMSG 0 #endif #define nn_errstr() nn_strerror(nn_errno()) diff --git a/crypto777/nanosrc/transports/utils/tcpmux.c b/crypto777/nanosrc/transports/utils/tcpmux.c index b6cd7c24b..9f2cc3a60 100755 --- a/crypto777/nanosrc/transports/utils/tcpmux.c +++ b/crypto777/nanosrc/transports/utils/tcpmux.c @@ -83,7 +83,7 @@ int tcpmux_accept (int s) memset (&hdr, 0, sizeof (hdr)); hdr.msg_iov = &iov; hdr.msg_iovlen = 1; -#ifndef NN_USE_MYMSG +#if !NN_USE_MYMSG unsigned char buf [256]; hdr.msg_control = buf; hdr.msg_controllen = sizeof (buf); diff --git a/crypto777/nanosrc/transports/ws/sws.c b/crypto777/nanosrc/transports/ws/sws.c index 45f5430cc..65c1bb384 100755 --- a/crypto777/nanosrc/transports/ws/sws.c +++ b/crypto777/nanosrc/transports/ws/sws.c @@ -370,7 +370,7 @@ static int nn_sws_send (struct nn_pipebase *self, struct nn_msg *msg) struct nn_cmsghdr *cmsg; struct nn_msghdr msghdr; uint8_t rand_mask [NN_SWS_FRAME_SIZE_MASK]; - +printf("nn_sws_send\n"); sws = nn_cont (self, struct nn_sws, pipebase); nn_assert_state (sws, NN_SWS_STATE_ACTIVE); From 2fc37f4310e653d4065c760f4eb53ef69fc47495 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Oct 2017 23:36:38 +0300 Subject: [PATCH 02/63] Test --- crypto777/nanosrc/nn_config.h | 4 ++-- iguana/exchanges/LP_prices.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto777/nanosrc/nn_config.h b/crypto777/nanosrc/nn_config.h index d98b64038..74edc6229 100755 --- a/crypto777/nanosrc/nn_config.h +++ b/crypto777/nanosrc/nn_config.h @@ -58,10 +58,10 @@ performance optimal make sure that this value is larger than network MTU. */ #define NN_USOCK_BATCH_SIZE (2048) //#define NN_USOCK_BATCH_SIZE (_NN_USOCK_BATCH_SIZE - 5 - 256 - 16) // adjust for veclen/clen + sizeof(ctrl) -#define NN_USE_MYMSG 0 +#define NN_USE_MYMSG 1 #if defined __PNACL || defined __APPLE__ -#define NN_USE_MYMSG 0 +#define NN_USE_MYMSG 1 #endif #define nn_errstr() nn_strerror(nn_errno()) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 4b4113f42..fdc14779c 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -685,7 +685,7 @@ void LP_pubkeys_query() reqjson = cJSON_CreateObject(); jaddstr(reqjson,"method","wantnotify"); jaddbits256(reqjson,"pub",pubp->pubkey); - printf("LP_pubkeys_query %s\n",jprint(reqjson,0)); + //printf("LP_pubkeys_query %s\n",jprint(reqjson,0)); LP_reserved_msg("","",zero,jprint(reqjson,1)); } } From 06f9b1794a782a92ca0b555fee922f5e68b80452 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Oct 2017 23:51:57 +0300 Subject: [PATCH 03/63] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index eeb23603f..27b437469 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -30,7 +30,7 @@ uint16_t Numpsocks,Psockport = MIN_PSOCK_PORT; char *nanomsg_transportname(int32_t bindflag,char *str,char *ipaddr,uint16_t port) { - sprintf(str,"ws://%s:%u",bindflag == 0 ? ipaddr : "*",port); // ws is worse + sprintf(str,"tcp://%s:%u",bindflag == 0 ? ipaddr : "*",port); // ws is worse return(str); } From 87e78ef35908b430c36efc3af320ed04a991fb86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 00:05:50 +0300 Subject: [PATCH 04/63] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 27b437469..eeb23603f 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -30,7 +30,7 @@ uint16_t Numpsocks,Psockport = MIN_PSOCK_PORT; char *nanomsg_transportname(int32_t bindflag,char *str,char *ipaddr,uint16_t port) { - sprintf(str,"tcp://%s:%u",bindflag == 0 ? ipaddr : "*",port); // ws is worse + sprintf(str,"ws://%s:%u",bindflag == 0 ? ipaddr : "*",port); // ws is worse return(str); } From fdf629ed08331e0d84d502a547f05339beab8767 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 00:14:43 +0300 Subject: [PATCH 05/63] Test --- crypto777/nanosrc/aio/usock_posix.c_dev | 2 +- crypto777/nanosrc/protocols/pipeline/xpush.c | 1 + crypto777/nanosrc/protocols/utils/lb.c | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crypto777/nanosrc/aio/usock_posix.c_dev b/crypto777/nanosrc/aio/usock_posix.c_dev index e5b8a1c35..244b0753c 100755 --- a/crypto777/nanosrc/aio/usock_posix.c_dev +++ b/crypto777/nanosrc/aio/usock_posix.c_dev @@ -1000,7 +1000,7 @@ static int32_t nn_usock_send_raw(struct nn_usock *self,struct msghdr *hdr) #else nbytes = sendmsg(self->s,hdr,0); #endif - PostMessage("nn_usock_send_raw nbytes.%d for sock.%d\n",(int32_t)nbytes,self->s); + printf("nn_usock_send_raw nbytes.%d for sock.%d\n",(int32_t)nbytes,self->s); if ( nn_slow(nbytes < 0) ) // Handle errors { if ( nn_fast(errno == EAGAIN || errno == EWOULDBLOCK) ) diff --git a/crypto777/nanosrc/protocols/pipeline/xpush.c b/crypto777/nanosrc/protocols/pipeline/xpush.c index 2d938bd1f..75f4ba610 100755 --- a/crypto777/nanosrc/protocols/pipeline/xpush.c +++ b/crypto777/nanosrc/protocols/pipeline/xpush.c @@ -160,6 +160,7 @@ static int nn_xpush_events (struct nn_sockbase *self) static int nn_xpush_send (struct nn_sockbase *self, struct nn_msg *msg) { + printf("nn_xpush_send\n"); return nn_lb_send (&nn_cont (self, struct nn_xpush, sockbase)->lb, msg, NULL); } diff --git a/crypto777/nanosrc/protocols/utils/lb.c b/crypto777/nanosrc/protocols/utils/lb.c index f0e2e88e3..90e31b92d 100755 --- a/crypto777/nanosrc/protocols/utils/lb.c +++ b/crypto777/nanosrc/protocols/utils/lb.c @@ -68,14 +68,16 @@ int nn_lb_send (struct nn_lb *self, struct nn_msg *msg, struct nn_pipe **to) { int rc; struct nn_pipe *pipe; - + printf("nn_lb_send\n"); /* Pipe is NULL only when there are no avialable pipes. */ pipe = nn_priolist_getpipe (&self->priolist); + printf("nn_lb_send pipe.%p\n",pipe); if (nn_slow (!pipe)) return -EAGAIN; /* Send the messsage. */ rc = nn_pipe_send (pipe, msg); + printf("nn_pipe_send rc.%d\n",rc); errnum_assert (rc >= 0, -rc); /* Move to the next pipe. */ From 7d7f4898274a45f7cd0aab7707dac9638143929b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 00:24:22 +0300 Subject: [PATCH 06/63] Test --- crypto777/nanosrc/protocols/pipeline/xpush.c | 2 +- crypto777/nanosrc/protocols/reqrep/xreq.c | 2 +- crypto777/nanosrc/protocols/utils/lb.c | 3 +-- crypto777/nanosrc/protocols/utils/priolist.c | 6 +++--- crypto777/nanosrc/protocols/utils/priolist.h | 3 +-- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/crypto777/nanosrc/protocols/pipeline/xpush.c b/crypto777/nanosrc/protocols/pipeline/xpush.c index 75f4ba610..10c5cf480 100755 --- a/crypto777/nanosrc/protocols/pipeline/xpush.c +++ b/crypto777/nanosrc/protocols/pipeline/xpush.c @@ -115,7 +115,7 @@ static int nn_xpush_add (struct nn_sockbase *self, struct nn_pipe *pipe) alloc_assert (data); nn_pipe_setdata (pipe, data); nn_lb_add (&xpush->lb, &data->lb, pipe, sndprio); - + printf("nn_xpush_add\n"); return 0; } diff --git a/crypto777/nanosrc/protocols/reqrep/xreq.c b/crypto777/nanosrc/protocols/reqrep/xreq.c index 7b96ba744..7ab93d201 100755 --- a/crypto777/nanosrc/protocols/reqrep/xreq.c +++ b/crypto777/nanosrc/protocols/reqrep/xreq.c @@ -101,7 +101,7 @@ int nn_xreq_add(struct nn_sockbase *self, struct nn_pipe *pipe) nn_pipe_setdata(pipe,data); nn_lb_add(&xreq->lb,&data->lb,pipe,sndprio); nn_fq_add(&xreq->fq,&data->fq,pipe,rcvprio); - + printf("nn_xreq_add\n"); return 0; } diff --git a/crypto777/nanosrc/protocols/utils/lb.c b/crypto777/nanosrc/protocols/utils/lb.c index 90e31b92d..cbff61f2f 100755 --- a/crypto777/nanosrc/protocols/utils/lb.c +++ b/crypto777/nanosrc/protocols/utils/lb.c @@ -37,8 +37,7 @@ void nn_lb_term (struct nn_lb *self) nn_priolist_term (&self->priolist); } -void nn_lb_add (struct nn_lb *self, struct nn_lb_data *data, - struct nn_pipe *pipe, int priority) +void nn_lb_add (struct nn_lb *self, struct nn_lb_data *data,struct nn_pipe *pipe, int priority) { nn_priolist_add (&self->priolist, &data->priodata, pipe, priority); } diff --git a/crypto777/nanosrc/protocols/utils/priolist.c b/crypto777/nanosrc/protocols/utils/priolist.c index a72b5d535..5d5560229 100755 --- a/crypto777/nanosrc/protocols/utils/priolist.c +++ b/crypto777/nanosrc/protocols/utils/priolist.c @@ -54,7 +54,7 @@ void nn_priolist_add(struct nn_priolist *self,struct nn_priolist_data *data, str { data->pipe = pipe; data->priority = priority; - //printf("nn_priolist_add.%p data.%p priority.%d\n",self,data,priority); + printf("nn_priolist_add.%p data.%p priority.%d\n",self,data,priority); nn_list_item_init (&data->item); } @@ -136,10 +136,10 @@ struct nn_pipe *nn_priolist_getpipe(struct nn_priolist *self) { if ( nn_slow(self->current == -1) ) { - //printf("nn_priolist_getpipe.%p -1 current it is\n",self); + printf("nn_priolist_getpipe.%p -1 current it is\n",self); return NULL; } - //printf("nn_priolist_getpipe.%p current.%d slot.%p\n",self,self->current,self->slots[self->current - 1].current->pipe); + printf("nn_priolist_getpipe.%p current.%d slot.%p\n",self,self->current,self->slots[self->current - 1].current->pipe); return self->slots[self->current - 1].current->pipe; } diff --git a/crypto777/nanosrc/protocols/utils/priolist.h b/crypto777/nanosrc/protocols/utils/priolist.h index 9d4a9cad7..358faae79 100755 --- a/crypto777/nanosrc/protocols/utils/priolist.h +++ b/crypto777/nanosrc/protocols/utils/priolist.h @@ -86,8 +86,7 @@ void nn_priolist_activate (struct nn_priolist *self, struct nn_priolist_data *da 0 otherwise. */ int nn_priolist_is_active (struct nn_priolist *self); -/* Get the pointer to the current pipe. If there's no pipe in the list, - NULL is returned. */ +// Get the pointer to the current pipe. If there's no pipe in the list, NULL is returned. struct nn_pipe *nn_priolist_getpipe (struct nn_priolist *self); /* Moves to the next pipe in the list. If 'release' is set to 1, the current From 0918e5da8c8ca70debafe0459943e8d5fde584ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 00:32:14 +0300 Subject: [PATCH 07/63] Test --- crypto777/nanosrc/transports/ws/cws.c | 4 +++- crypto777/nanosrc/transports/ws/ws.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crypto777/nanosrc/transports/ws/cws.c b/crypto777/nanosrc/transports/ws/cws.c index 57e66c91a..905e90405 100755 --- a/crypto777/nanosrc/transports/ws/cws.c +++ b/crypto777/nanosrc/transports/ws/cws.c @@ -329,7 +329,7 @@ static void nn_cws_handler (struct nn_fsm *self, int src, int type, struct nn_cws *cws; cws = nn_cont (self, struct nn_cws, fsm); - + printf("cws_handler src.%d type.%d state.%d\n",src,type,cws->state); switch (cws->state) { /******************************************************************************/ @@ -409,6 +409,7 @@ static void nn_cws_handler (struct nn_fsm *self, int src, int type, case NN_CWS_SRC_USOCK: switch (type) { case NN_USOCK_CONNECTED: + printf("cws connected\n"); nn_sws_start (&cws->sws, &cws->usock, NN_WS_CLIENT, nn_chunkref_data (&cws->resource), nn_chunkref_data (&cws->remote_host)); @@ -421,6 +422,7 @@ static void nn_cws_handler (struct nn_fsm *self, int src, int type, nn_epbase_clear_error (&cws->epbase); return; case NN_USOCK_ERROR: + printf("cws NN_USOCK_ERROR\n"); nn_epbase_set_error (&cws->epbase,nn_usock_geterrno (&cws->usock),__FILE__,__LINE__); nn_usock_stop(&cws->usock); cws->state = NN_CWS_STATE_STOPPING_USOCK; diff --git a/crypto777/nanosrc/transports/ws/ws.c b/crypto777/nanosrc/transports/ws/ws.c index 0e91e9474..3a9288284 100755 --- a/crypto777/nanosrc/transports/ws/ws.c +++ b/crypto777/nanosrc/transports/ws/ws.c @@ -156,7 +156,7 @@ int nn_ws_send (int s, const void *msg, size_t len, uint8_t msg_type, int flags) struct nn_msghdr hdr; struct nn_cmsghdr *cmsg; size_t cmsgsz; - +printf("nn_ws_send\n"); iov.iov_base = (void*) msg; iov.iov_len = len; From 6a192e19bcf54e3a46cf89f38ff89843cc3bf457 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 00:37:51 +0300 Subject: [PATCH 08/63] Test --- crypto777/nanosrc/utils/thread_posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/nanosrc/utils/thread_posix.c b/crypto777/nanosrc/utils/thread_posix.c index 32c8428e4..eeaf30aed 100755 --- a/crypto777/nanosrc/utils/thread_posix.c +++ b/crypto777/nanosrc/utils/thread_posix.c @@ -30,7 +30,7 @@ static void *nn_thread_main_routine(void *arg) { struct nn_thread *self; self = (struct nn_thread *)arg; - PNACL_msg("nn_thread_main_routine arg.%p self->routine(%p) at %p\n",arg,self->arg,self->routine); + printf("nn_thread_main_routine arg.%p self->routine(%p) at %p\n",arg,self->arg,self->routine); self->routine(self->arg); // Run the thread routine return NULL; } @@ -47,7 +47,7 @@ void nn_thread_init(struct nn_thread *self,nn_thread_routine *routine,void *arg) { int32_t rc; // No signals should be processed by this thread. The library doesn't use signals and thus all the signals should be delivered to application threads, not to worker threads. - PNACL_msg("nn_thread_init routine.%p arg.%p\n",routine,arg); + printf("nn_thread_init routine.%p arg.%p\n",routine,arg); self->routine = routine; self->arg = arg; rc = pthread_create(&self->handle,NULL,nn_thread_main_routine,(void *)self); From a1a0c2dc8b1f8fbffc085eccdef5fcdf7c13e7e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 00:40:36 +0300 Subject: [PATCH 09/63] Test --- crypto777/nanosrc/aio/worker_posix.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crypto777/nanosrc/aio/worker_posix.c b/crypto777/nanosrc/aio/worker_posix.c index 8d3ed2a46..48ee252a5 100755 --- a/crypto777/nanosrc/aio/worker_posix.c +++ b/crypto777/nanosrc/aio/worker_posix.c @@ -173,7 +173,7 @@ static void nn_worker_routine (void *arg) struct nn_worker_task *task; struct nn_worker_fd *fd; struct nn_worker_timer *timer; - PNACL_msg("nn_worker_routine started\n"); + printf("nn_worker_routine started\n"); self = (struct nn_worker*) arg; while ( 1 ) // Infinite loop. It will be interrupted only when the object is shut down. { @@ -185,7 +185,7 @@ static void nn_worker_routine (void *arg) rc = nn_timerset_event(&self->timerset, &thndl); if ( rc == -EAGAIN ) break; - PNACL_msg("nn_worker process expired user\n"); + printf("nn_worker process expired user\n"); errnum_assert(rc == 0, -rc); timer = nn_cont(thndl, struct nn_worker_timer, hndl); nn_ctx_enter(timer->owner->ctx); @@ -197,7 +197,7 @@ static void nn_worker_routine (void *arg) rc = nn_poller_event(&self->poller,&pevent,&phndl); // Get next poller event, such as IN or OUT if ( nn_slow(rc == -EAGAIN) ) break; - PNACL_msg("nn_worker process all events from the poller\n"); + printf("nn_worker process all events from the poller\n"); if ( phndl == &self->efd_hndl ) // If there are any new incoming worker tasks, process them { nn_assert (pevent == NN_POLLER_IN); @@ -212,14 +212,14 @@ static void nn_worker_routine (void *arg) item = nn_queue_pop(&tasks); // Next worker task if ( nn_slow(!item) ) break; - PNACL_msg("nn_worker next worker task\n"); + printf("nn_worker next worker task\n"); if ( nn_slow(item == &self->stop) ) // If the worker thread is asked to stop, do so { nn_queue_term(&tasks); return; } // It's a user-defined task. Notify the user that it has arrived in the worker thread - PNACL_msg("nn_worker user defined task\n"); + printf("nn_worker user defined task\n"); task = nn_cont(item,struct nn_worker_task,item); nn_ctx_enter(task->owner->ctx); nn_fsm_feed(task->owner,task->src,NN_WORKER_TASK_EXECUTE,task); @@ -228,15 +228,15 @@ static void nn_worker_routine (void *arg) nn_queue_term (&tasks); continue; } - PNACL_msg("nn_worker true i/o, invoke handler\n"); + printf("nn_worker true i/o, invoke handler\n"); fd = nn_cont(phndl,struct nn_worker_fd,hndl); // It's a true I/O event. Invoke the handler - PNACL_msg("nn_worker true i/o, fd.%p\n",fd); + printf("nn_worker true i/o, fd.%p\n",fd); nn_ctx_enter(fd->owner->ctx); - PNACL_msg("nn_worker true i/o, after nn_ctx_enter\n"); + printf("nn_worker true i/o, after nn_ctx_enter\n"); nn_fsm_feed(fd->owner,fd->src,pevent,fd); - PNACL_msg("nn_worker true i/o, after nn_fsm_feed leave.%p\n",fd->owner->ctx); + printf("nn_worker true i/o, after nn_fsm_feed leave.%p\n",fd->owner->ctx); nn_ctx_leave(fd->owner->ctx); - PNACL_msg("nn_worker true i/o, after nn_ctx_leave\n"); + printf("nn_worker true i/o, after nn_ctx_leave\n"); } } } From 5c40e6118f42d663ce31d8cc05fcaeb249539f9b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:00:12 +0300 Subject: [PATCH 10/63] Test --- crypto777/nanosrc/aio/worker_posix.c | 7 ++++++ crypto777/nanosrc/utils/thread_posix.c | 6 +++++ iguana/exchanges/LP_nativeDEX.c | 31 ++++++++++++++------------ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/crypto777/nanosrc/aio/worker_posix.c b/crypto777/nanosrc/aio/worker_posix.c index 48ee252a5..550aa31f4 100755 --- a/crypto777/nanosrc/aio/worker_posix.c +++ b/crypto777/nanosrc/aio/worker_posix.c @@ -175,7 +175,9 @@ static void nn_worker_routine (void *arg) struct nn_worker_timer *timer; printf("nn_worker_routine started\n"); self = (struct nn_worker*) arg; +#ifndef FROM_JS while ( 1 ) // Infinite loop. It will be interrupted only when the object is shut down. +#endif { // Wait for new events and/or timeouts. rc = nn_poller_wait(&self->poller,nn_timerset_timeout (&self->timerset)); @@ -226,7 +228,12 @@ static void nn_worker_routine (void *arg) nn_ctx_leave (task->owner->ctx); } nn_queue_term (&tasks); +#ifdef FROM_JS + printf("done worker ITER\n"); + return; +#else continue; +#endif } printf("nn_worker true i/o, invoke handler\n"); fd = nn_cont(phndl,struct nn_worker_fd,hndl); // It's a true I/O event. Invoke the handler diff --git a/crypto777/nanosrc/utils/thread_posix.c b/crypto777/nanosrc/utils/thread_posix.c index eeaf30aed..fc27a6711 100755 --- a/crypto777/nanosrc/utils/thread_posix.c +++ b/crypto777/nanosrc/utils/thread_posix.c @@ -42,6 +42,8 @@ void nn_thread_term(struct nn_thread *self) errnum_assert(rc == 0,rc); } +void *Nanomsg_threadarg; + #ifdef __PNACL void nn_thread_init(struct nn_thread *self,nn_thread_routine *routine,void *arg) { @@ -50,8 +52,12 @@ void nn_thread_init(struct nn_thread *self,nn_thread_routine *routine,void *arg) printf("nn_thread_init routine.%p arg.%p\n",routine,arg); self->routine = routine; self->arg = arg; +#ifdef FROM_JS + Nanomsg_threadarg = self; +#else rc = pthread_create(&self->handle,NULL,nn_thread_main_routine,(void *)self); errnum_assert (rc == 0, rc); +#endif } #else diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index aceba1ffd..7f342af44 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1031,11 +1031,26 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu } #ifdef FROM_JS +extern void *Nanomsg_threadarg; void emscripten_usleep(int32_t x) { } +char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params,int32_t timeout) +{ + static uint32_t counter; char fname[512],*retstr; long fsize; + if ( strncmp("http://",url,strlen("http://")) != 0 ) + return(clonestr("{\"error\":\"only http allowed\"}")); + sprintf(fname,"bitcoind_RPC/req.%u",counter); + counter++; + //printf("issue.(%s)\n",url); + emscripten_wget(url,fname); + retstr = OS_filestr(&fsize,fname); + //printf("bitcoind_RPC(%s) -> fname.(%s) %s\n",url,fname,retstr); + return(retstr); +} + void LP_fromjs_iter() { static void *ctx; @@ -1048,6 +1063,8 @@ void LP_fromjs_iter() ctx = bitcoin_ctx(); if ( 0 && (LP_counter % 100) == 0 ) printf("LP_fromjs_iter got called LP_counter.%d userpass.(%s) ctx.%p\n",LP_counter,G.USERPASS,ctx); + if ( Nanomsg_threadarg != 0 ) + nn_thread_main_routine(Nanomsg_threadarg); LP_pubkeys_query(); LP_utxosQ_process(); LP_nanomsg_recvs(ctx); @@ -1055,20 +1072,6 @@ void LP_fromjs_iter() LP_counter++; } -char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params,int32_t timeout) -{ - static uint32_t counter; char fname[512],*retstr; long fsize; - if ( strncmp("http://",url,strlen("http://")) != 0 ) - return(clonestr("{\"error\":\"only http allowed\"}")); - sprintf(fname,"bitcoind_RPC/req.%u",counter); - counter++; - //printf("issue.(%s)\n",url); - emscripten_wget(url,fname); - retstr = OS_filestr(&fsize,fname); - //printf("bitcoind_RPC(%s) -> fname.(%s) %s\n",url,fname,retstr); - return(retstr); -} - #endif From fa5944a7f4b89d3a84e36a498b7f6e4463a221d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:01:59 +0300 Subject: [PATCH 11/63] Test --- crypto777/nanosrc/utils/thread_posix.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crypto777/nanosrc/utils/thread_posix.c b/crypto777/nanosrc/utils/thread_posix.c index fc27a6711..df005eee3 100755 --- a/crypto777/nanosrc/utils/thread_posix.c +++ b/crypto777/nanosrc/utils/thread_posix.c @@ -26,7 +26,7 @@ #include #include -static void *nn_thread_main_routine(void *arg) +void *nn_thread_main_routine(void *arg) { struct nn_thread *self; self = (struct nn_thread *)arg; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7f342af44..8f7bcf9a6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1032,6 +1032,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu #ifdef FROM_JS extern void *Nanomsg_threadarg; +void *nn_thread_main_routine(void *arg); void emscripten_usleep(int32_t x) { From c35f95d7303bd7cfbf22e13b5aa74180dfcf02a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:08:30 +0300 Subject: [PATCH 12/63] Test --- crypto777/nanosrc/core/pipe.c | 1 + crypto777/nanosrc/nn_config.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crypto777/nanosrc/core/pipe.c b/crypto777/nanosrc/core/pipe.c index a025d1f00..1b1cd1dc6 100755 --- a/crypto777/nanosrc/core/pipe.c +++ b/crypto777/nanosrc/core/pipe.c @@ -176,6 +176,7 @@ int nn_pipe_send(struct nn_pipe *self,struct nn_msg *msg) int rc; struct nn_pipebase *pipebase; pipebase = (struct nn_pipebase *)self; + printf("pipesend\n"); nn_assert (pipebase->outstate == NN_PIPEBASE_OUTSTATE_IDLE); pipebase->outstate = NN_PIPEBASE_OUTSTATE_SENDING; rc = pipebase->vfptr->send(pipebase,msg); diff --git a/crypto777/nanosrc/nn_config.h b/crypto777/nanosrc/nn_config.h index 74edc6229..dc864bfbd 100755 --- a/crypto777/nanosrc/nn_config.h +++ b/crypto777/nanosrc/nn_config.h @@ -31,8 +31,8 @@ #define NN_HAVE_SEMAPHORE 1 // must have // need one of following 3, listed in order of precedence, used by efd* -//#define NN_HAVE_EVENTFD 1 -#define NN_HAVE_PIPE 1 +#define NN_HAVE_EVENTFD 1 +//#define NN_HAVE_PIPE 1 //#define NN_HAVE_SOCKETPAIR 1 // need one of following 3, listed in order of precedence, used by poller* From c377215d5b7835f4d71b541669e35185343af366 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:09:50 +0300 Subject: [PATCH 13/63] Test --- crypto777/nanosrc/nn_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/nanosrc/nn_config.h b/crypto777/nanosrc/nn_config.h index dc864bfbd..0d4d15c2c 100755 --- a/crypto777/nanosrc/nn_config.h +++ b/crypto777/nanosrc/nn_config.h @@ -31,9 +31,9 @@ #define NN_HAVE_SEMAPHORE 1 // must have // need one of following 3, listed in order of precedence, used by efd* -#define NN_HAVE_EVENTFD 1 +//#define NN_HAVE_EVENTFD 1 //#define NN_HAVE_PIPE 1 -//#define NN_HAVE_SOCKETPAIR 1 +#define NN_HAVE_SOCKETPAIR 1 // need one of following 3, listed in order of precedence, used by poller* #define NN_USE_POLL 1 From d1bb5fbcebfd71785af3bb5ecd98f081dd3d7e8e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:12:28 +0300 Subject: [PATCH 14/63] Test --- iguana/exchanges/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/Makefile b/iguana/exchanges/Makefile index 0048287e2..f12cccf2e 100644 --- a/iguana/exchanges/Makefile +++ b/iguana/exchanges/Makefile @@ -4,5 +4,5 @@ include ../crypto777/crypto777.sources all: - emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -D__PNACL -DFROM_JS -O2 -I../includes -I../crypto777 -s PTHREAD_POOL_SIZE=8 -s USE_PTHREADS=1 -o /var/www/html/index.html exchanges/mm.c $(CRYPTO777_SRCS) mini-gmp.c secp256k1/src/secp256k1.c -lm + emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -D__PNACL -DFROM_JS -O2 -I../includes -I../crypto777 -s PTHREAD_POOL_SIZE=8 -s USE_PTHREADS=1 -o /var/www/html/index.html exchanges/mm.c $(CRYPTO777_SRCS) mini-gmp.c secp256k1/src/secp256k1.c -lm -lc From 6eb96d54dcefbf3ff59f74cdc7432678e284807d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:14:42 +0300 Subject: [PATCH 15/63] Test --- crypto777/nanosrc/nn_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/nanosrc/nn_config.h b/crypto777/nanosrc/nn_config.h index 0d4d15c2c..dc864bfbd 100755 --- a/crypto777/nanosrc/nn_config.h +++ b/crypto777/nanosrc/nn_config.h @@ -31,9 +31,9 @@ #define NN_HAVE_SEMAPHORE 1 // must have // need one of following 3, listed in order of precedence, used by efd* -//#define NN_HAVE_EVENTFD 1 +#define NN_HAVE_EVENTFD 1 //#define NN_HAVE_PIPE 1 -#define NN_HAVE_SOCKETPAIR 1 +//#define NN_HAVE_SOCKETPAIR 1 // need one of following 3, listed in order of precedence, used by poller* #define NN_USE_POLL 1 From c8c945c3ccdf554c88b0bcb6b3b549b10e69cb1e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:16:47 +0300 Subject: [PATCH 16/63] test --- crypto777/nanosrc/nn_config.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto777/nanosrc/nn_config.h b/crypto777/nanosrc/nn_config.h index dc864bfbd..2a781e8c1 100755 --- a/crypto777/nanosrc/nn_config.h +++ b/crypto777/nanosrc/nn_config.h @@ -31,13 +31,13 @@ #define NN_HAVE_SEMAPHORE 1 // must have // need one of following 3, listed in order of precedence, used by efd* -#define NN_HAVE_EVENTFD 1 -//#define NN_HAVE_PIPE 1 +//#define NN_HAVE_EVENTFD 1 +#define NN_HAVE_PIPE 1 //#define NN_HAVE_SOCKETPAIR 1 // need one of following 3, listed in order of precedence, used by poller* -#define NN_USE_POLL 1 -//#define NN_USE_EPOLL 1 +//#define NN_USE_POLL 1 +#define NN_USE_EPOLL 1 //#define NN_USE_KQUEUE 1 #define NN_DISABLE_GETADDRINFO_A 1 From ee9b679045447c069880c750729a30c18cfe24a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:17:19 +0300 Subject: [PATCH 17/63] Test --- crypto777/nanosrc/nn_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/nanosrc/nn_config.h b/crypto777/nanosrc/nn_config.h index 2a781e8c1..74edc6229 100755 --- a/crypto777/nanosrc/nn_config.h +++ b/crypto777/nanosrc/nn_config.h @@ -36,8 +36,8 @@ //#define NN_HAVE_SOCKETPAIR 1 // need one of following 3, listed in order of precedence, used by poller* -//#define NN_USE_POLL 1 -#define NN_USE_EPOLL 1 +#define NN_USE_POLL 1 +//#define NN_USE_EPOLL 1 //#define NN_USE_KQUEUE 1 #define NN_DISABLE_GETADDRINFO_A 1 From 54d1ad3ba2adaed906a461150ea0b2631aa8f5b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:26:36 +0300 Subject: [PATCH 18/63] Test --- iguana/exchanges/LP_nativeDEX.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8f7bcf9a6..72f7fa84f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1031,8 +1031,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu } #ifdef FROM_JS -extern void *Nanomsg_threadarg; -void *nn_thread_main_routine(void *arg); +//extern void *Nanomsg_threadarg; +//void *nn_thread_main_routine(void *arg); void emscripten_usleep(int32_t x) { @@ -1064,8 +1064,8 @@ void LP_fromjs_iter() ctx = bitcoin_ctx(); if ( 0 && (LP_counter % 100) == 0 ) printf("LP_fromjs_iter got called LP_counter.%d userpass.(%s) ctx.%p\n",LP_counter,G.USERPASS,ctx); - if ( Nanomsg_threadarg != 0 ) - nn_thread_main_routine(Nanomsg_threadarg); + //if ( Nanomsg_threadarg != 0 ) + // nn_thread_main_routine(Nanomsg_threadarg); LP_pubkeys_query(); LP_utxosQ_process(); LP_nanomsg_recvs(ctx); From 14c7a7b8ad2657960ef3c16dfec6eb238accbd15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:36:41 +0300 Subject: [PATCH 19/63] Test --- iguana/exchanges/LP_nativeDEX.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 72f7fa84f..8f7bcf9a6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1031,8 +1031,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu } #ifdef FROM_JS -//extern void *Nanomsg_threadarg; -//void *nn_thread_main_routine(void *arg); +extern void *Nanomsg_threadarg; +void *nn_thread_main_routine(void *arg); void emscripten_usleep(int32_t x) { @@ -1064,8 +1064,8 @@ void LP_fromjs_iter() ctx = bitcoin_ctx(); if ( 0 && (LP_counter % 100) == 0 ) printf("LP_fromjs_iter got called LP_counter.%d userpass.(%s) ctx.%p\n",LP_counter,G.USERPASS,ctx); - //if ( Nanomsg_threadarg != 0 ) - // nn_thread_main_routine(Nanomsg_threadarg); + if ( Nanomsg_threadarg != 0 ) + nn_thread_main_routine(Nanomsg_threadarg); LP_pubkeys_query(); LP_utxosQ_process(); LP_nanomsg_recvs(ctx); From a91e379e688266d61e6a5a0fb7f19bb42c1a569f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:39:13 +0300 Subject: [PATCH 20/63] Test --- iguana/exchanges/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/Makefile b/iguana/exchanges/Makefile index f12cccf2e..7d315ff5f 100644 --- a/iguana/exchanges/Makefile +++ b/iguana/exchanges/Makefile @@ -1,8 +1,10 @@ #cd .. #emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -DFROM_JS -O2 -I../includes -I../crypto777 -s PTHREAD_POOL_SIZE=8 -s USE_PTHREADS=1 -o /var/www/html/index.html exchanges/mm.c ../crypto777/*.c ../crypto777/jpeg/*.c ../crypto777/jpeg/unix/*.c mini-gmp.c secp256k1/src/secp256k1.c -lm ../OSlibs/js/libnanomsg.a -lc -lpthread +#emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -D__PNACL -DFROM_JS -O2 -I../includes -I../crypto777 -s PTHREAD_POOL_SIZE=8 -s USE_PTHREADS=1 -o /var/www/html/index.html exchanges/mm.c $(CRYPTO777_SRCS) mini-gmp.c secp256k1/src/secp256k1.c -lm -lc + include ../crypto777/crypto777.sources all: - emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -D__PNACL -DFROM_JS -O2 -I../includes -I../crypto777 -s PTHREAD_POOL_SIZE=8 -s USE_PTHREADS=1 -o /var/www/html/index.html exchanges/mm.c $(CRYPTO777_SRCS) mini-gmp.c secp256k1/src/secp256k1.c -lm -lc + emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -D__PNACL -DFROM_JS -O2 -I../includes -I../crypto777 -o /var/www/html/index.html exchanges/mm.c $(CRYPTO777_SRCS) mini-gmp.c secp256k1/src/secp256k1.c -lm -lc From 0762b303cf3d6dff844262f5631e9d11d1b4bc0f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:50:13 +0300 Subject: [PATCH 21/63] Test --- crypto777/nanosrc/core/global.c | 3 +++ crypto777/nanosrc/core/sock.c | 7 +++++-- crypto777/nanosrc/transports/ws/sws.c | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crypto777/nanosrc/core/global.c b/crypto777/nanosrc/core/global.c index c654753fd..83b8e63d0 100755 --- a/crypto777/nanosrc/core/global.c +++ b/crypto777/nanosrc/core/global.c @@ -1276,7 +1276,10 @@ static int nn_global_create_ep (int s, const char *addr, int bind) tp = NULL; } if ( !tp ) // The protocol specified doesn't match any known protocol + { + printf("unknown protocol\n"); return -EPROTONOSUPPORT; + } rc = nn_sock_add_ep (SELF.socks [s], tp, bind, addr); // Ask the socket to create the endpoint return rc; } diff --git a/crypto777/nanosrc/core/sock.c b/crypto777/nanosrc/core/sock.c index 7427a5fc4..ee95034a8 100755 --- a/crypto777/nanosrc/core/sock.c +++ b/crypto777/nanosrc/core/sock.c @@ -477,6 +477,7 @@ struct nn_ep *nn_find_ep(struct nn_sock *self,int32_t eid,const char *addr,struc int nn_sock_add_ep(struct nn_sock *self,struct nn_transport *transport,int32_t bind,const char *addr) { int rc,eid; struct nn_ep *ep; + printf("nn_sock_add_ep\n"); nn_ctx_enter (&self->ctx); if ( (ep= nn_find_ep(self,0,addr,transport,bind)) == NULL ) // The endpoint doesn't exist { @@ -484,16 +485,17 @@ int nn_sock_add_ep(struct nn_sock *self,struct nn_transport *transport,int32_t b rc = nn_ep_init(ep,NN_SOCK_SRC_EP,self,self->eid,transport,bind,addr); if ( nn_slow(rc < 0) ) { + printf("nn_sock_add_ep nn_ep_init rc.%d\n",rc); nn_free(ep); nn_ctx_leave(&self->ctx); return rc; } nn_ep_start(ep); - PNACL_msg("ep sock.(%s) started %s://(%s) bind.%d\n",self->socket_name,transport->name,addr,bind); + printf("ep sock.(%s) started %s://(%s) bind.%d\n",self->socket_name,transport->name,addr,bind); eid = self->eid++; // Increase the endpoint ID for the next endpoint nn_list_insert(&self->eps,&ep->item,nn_list_end(&self->eps)); // Add to the list of active endpoints nn_ctx_leave (&self->ctx); - } else PNACL_msg("self->sock.(%s) %p already has (%s)\n",self->socket_name,self->sockbase->sock,addr); + } else printf("self->sock.(%s) %p already has (%s)\n",self->socket_name,self->sockbase->sock,addr); return(ep->eid); } @@ -673,6 +675,7 @@ int nn_sock_add(struct nn_sock *self, struct nn_pipe *pipe) { int rc; rc = self->sockbase->vfptr->add(self->sockbase,pipe); + printf("nn_sock_add rc.%d\n",rc); if (nn_slow (rc >= 0)) { nn_sock_stat_increment (self, NN_STAT_CURRENT_CONNECTIONS, 1); } diff --git a/crypto777/nanosrc/transports/ws/sws.c b/crypto777/nanosrc/transports/ws/sws.c index 65c1bb384..627c5590f 100755 --- a/crypto777/nanosrc/transports/ws/sws.c +++ b/crypto777/nanosrc/transports/ws/sws.c @@ -884,7 +884,7 @@ static void nn_sws_handler (struct nn_fsm *self, int src, int type, int rc; sws = nn_cont (self, struct nn_sws, fsm); - + printf("sws src.%d type.%d state.%d\n",src,type,sws->state); switch (sws->state) { /******************************************************************************/ From 95e64aa9c4ce856449047c996afb9f620f4b7c91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:54:42 +0300 Subject: [PATCH 22/63] Test --- crypto777/nanosrc/transports/ws/cws.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crypto777/nanosrc/transports/ws/cws.c b/crypto777/nanosrc/transports/ws/cws.c index 905e90405..9de4ea5b4 100755 --- a/crypto777/nanosrc/transports/ws/cws.c +++ b/crypto777/nanosrc/transports/ws/cws.c @@ -329,7 +329,11 @@ static void nn_cws_handler (struct nn_fsm *self, int src, int type, struct nn_cws *cws; cws = nn_cont (self, struct nn_cws, fsm); - printf("cws_handler src.%d type.%d state.%d\n",src,type,cws->state); + int32_t rc = 0; + if ( type == 2 && cws->state == 3 ) + rc = nn_pipebase_start (&sws->pipebase); + printf("cws_handler src.%d type.%d state.%d rc.%d\n",src,type,cws->state,rc); + switch (cws->state) { /******************************************************************************/ From b7e0b668be4ee24b07faf6359b252d99b0f99648 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:55:19 +0300 Subject: [PATCH 23/63] Test --- crypto777/nanosrc/transports/ws/cws.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/nanosrc/transports/ws/cws.c b/crypto777/nanosrc/transports/ws/cws.c index 9de4ea5b4..3d5363969 100755 --- a/crypto777/nanosrc/transports/ws/cws.c +++ b/crypto777/nanosrc/transports/ws/cws.c @@ -331,7 +331,7 @@ static void nn_cws_handler (struct nn_fsm *self, int src, int type, cws = nn_cont (self, struct nn_cws, fsm); int32_t rc = 0; if ( type == 2 && cws->state == 3 ) - rc = nn_pipebase_start (&sws->pipebase); + rc = nn_pipebase_start (&cws->pipebase); printf("cws_handler src.%d type.%d state.%d rc.%d\n",src,type,cws->state,rc); switch (cws->state) { From a341b860e559b01f694c514049992aea29aef1f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 01:56:15 +0300 Subject: [PATCH 24/63] Test --- crypto777/nanosrc/transports/ws/cws.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crypto777/nanosrc/transports/ws/cws.c b/crypto777/nanosrc/transports/ws/cws.c index 3d5363969..905e90405 100755 --- a/crypto777/nanosrc/transports/ws/cws.c +++ b/crypto777/nanosrc/transports/ws/cws.c @@ -329,11 +329,7 @@ static void nn_cws_handler (struct nn_fsm *self, int src, int type, struct nn_cws *cws; cws = nn_cont (self, struct nn_cws, fsm); - int32_t rc = 0; - if ( type == 2 && cws->state == 3 ) - rc = nn_pipebase_start (&cws->pipebase); - printf("cws_handler src.%d type.%d state.%d rc.%d\n",src,type,cws->state,rc); - + printf("cws_handler src.%d type.%d state.%d\n",src,type,cws->state); switch (cws->state) { /******************************************************************************/ From 45e68b3e251bb96c8c56d3d5b63f9779ef600ae7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 15:51:40 +0300 Subject: [PATCH 25/63] Complete JS main iter --- iguana/exchanges/LP_nativeDEX.c | 47 +++++++++++++++++++++------------ iguana/exchanges/LP_network.c | 4 ++- iguana/exchanges/LP_portfolio.c | 6 ++++- iguana/exchanges/LP_stats.c | 8 ++++-- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8f7bcf9a6..29f7ba595 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -492,15 +492,18 @@ void LP_coinsloop(void *_coins) nonz = 0; HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - if ( coins[0] != 0 ) + if ( coins != 0 ) { - if ( strcmp(coins,coin->symbol) != 0 ) - continue; - } - else // avoid hardcode special case LP_coinsloop - { - if ( strcmp("BTC",coin->symbol) == 0 || strcmp("KMD",coin->symbol) == 0 ) - continue; + if ( coins[0] != 0 ) + { + if ( strcmp(coins,coin->symbol) != 0 ) + continue; + } + else // avoid hardcode special case LP_coinsloop + { + if ( strcmp("BTC",coin->symbol) == 0 || strcmp("KMD",coin->symbol) == 0 ) + continue; + } } memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) @@ -578,6 +581,8 @@ void LP_coinsloop(void *_coins) break; } } + if ( coins == 0 ) + return; if ( nonz == 0 ) usleep(1000); } @@ -793,7 +798,6 @@ void LP_reserved_msgs(void *ignore) int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg) { int32_t n = 0; -#ifndef FROM_JS portable_mutex_lock(&LP_reservedmutex); if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs) ) { @@ -801,10 +805,6 @@ int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg) n = num_Reserved_msgs; } else LP_broadcast_message(LP_mypubsock,base,rel,pubkey,msg); portable_mutex_unlock(&LP_reservedmutex); -#else - printf("reserved_msg.(%s)\n",msg); - LP_broadcast_message(LP_mypubsock,base,rel,pubkey,msg); -#endif if ( num_Reserved_msgs > max_Reserved_msgs ) { max_Reserved_msgs = num_Reserved_msgs; @@ -1054,7 +1054,7 @@ char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char * void LP_fromjs_iter() { - static void *ctx; + static void *ctx; char *retstr; if ( G.initializing != 0 ) { printf("LP_fromjs_iter during G.initializing, skip\n"); @@ -1064,12 +1064,25 @@ void LP_fromjs_iter() ctx = bitcoin_ctx(); if ( 0 && (LP_counter % 100) == 0 ) printf("LP_fromjs_iter got called LP_counter.%d userpass.(%s) ctx.%p\n",LP_counter,G.USERPASS,ctx); - if ( Nanomsg_threadarg != 0 ) - nn_thread_main_routine(Nanomsg_threadarg); - LP_pubkeys_query(); + //if ( Nanomsg_threadarg != 0 ) + // nn_thread_main_routine(Nanomsg_threadarg); + //LP_pubkeys_query(); LP_utxosQ_process(); LP_nanomsg_recvs(ctx); LP_mainloop_iter(ctx,LP_myipaddr,0,LP_mypubsock,LP_publicaddr,LP_RPCPORT); + queue_loop(0); + if ( (LP_counter % 10) == 0 ) + { + LP_coinsloop(0); + if ( (LP_counter % 100) == 0 ) + { + LP_notify_pubkeys(ctx,LP_mypubsock); + LP_privkey_updates(ctx,LP_mypubsock,0); + prices_loop(0); + if ( (retstr= basilisk_swapentry(0,0)) != 0 ) + free(retstr); + } + } LP_counter++; } diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index eeb23603f..09d387f37 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -139,7 +139,7 @@ int32_t LP_peerindsock(int32_t *peerindp) return(-1); } -void queue_loop(void *ignore) +void queue_loop(void *arg) { struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; while ( 1 ) @@ -195,6 +195,8 @@ void queue_loop(void *ignore) ptr = 0; } } + if ( arg == 0 ) + break; //if ( n != 0 ) // printf("LP_Q.[%d]\n",n); if ( nonz == 0 ) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index f3492daf6..dce7e3f99 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -595,13 +595,15 @@ int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *a return(n); } -void prices_loop(void *ignore) +void prices_loop(void *arg) { char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; void *ctx = bitcoin_ctx(); while ( 1 ) { if ( (btcpp= LP_priceinfofind("BTC")) == 0 ) { + if ( arg == 0 ) + return; sleep(60); continue; } @@ -635,6 +637,8 @@ void prices_loop(void *ignore) } free(retstr); } + if ( arg == 0 ) + return; sleep(60); } } diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index f5b244822..994292e17 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -38,8 +38,12 @@ void LP_tradecommand_log(cJSON *argjson) } } -uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_numridqids; -uint64_t Ridqids[128]; +static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_numridqids; + +struct LP_swapstats +{ + uint64_t aliceid; +}; uint64_t LP_aliceid_calc(bits256 desttxid,int32_t destvout,bits256 feetxid,int32_t feevout) { From 02be7bf6205d1cda524636da0ddfe1bc95791b1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 15:52:18 +0300 Subject: [PATCH 26/63] Test --- iguana/exchanges/LP_stats.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 994292e17..21228ef9c 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -44,6 +44,7 @@ struct LP_swapstats { uint64_t aliceid; }; +uint64_t Ridqids[128]; uint64_t LP_aliceid_calc(bits256 desttxid,int32_t destvout,bits256 feetxid,int32_t feevout) { From b6b8dbbe1a1a28394f476d3091a60ab8a733b570 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 15:55:16 +0300 Subject: [PATCH 27/63] Test --- crypto777/nanosrc/protocols/utils/priolist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/nanosrc/protocols/utils/priolist.c b/crypto777/nanosrc/protocols/utils/priolist.c index 5d5560229..5b6cb5401 100755 --- a/crypto777/nanosrc/protocols/utils/priolist.c +++ b/crypto777/nanosrc/protocols/utils/priolist.c @@ -136,7 +136,7 @@ struct nn_pipe *nn_priolist_getpipe(struct nn_priolist *self) { if ( nn_slow(self->current == -1) ) { - printf("nn_priolist_getpipe.%p -1 current it is\n",self); + //printf("nn_priolist_getpipe.%p -1 current it is\n",self); return NULL; } printf("nn_priolist_getpipe.%p current.%d slot.%p\n",self,self->current,self->slots[self->current - 1].current->pipe); From 33b8a3931e2375d65923433f6ebbb64e976d49c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 16:19:17 +0300 Subject: [PATCH 28/63] Test --- iguana/exchanges/LP_stats.c | 70 ++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 21228ef9c..62125740f 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -38,22 +38,50 @@ void LP_tradecommand_log(cJSON *argjson) } } -static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_numridqids; +static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_aliceids; struct LP_swapstats { + UT_hash_handle hh; + struct LP_quoteinfo Q; + double qprice; uint64_t aliceid; -}; -uint64_t Ridqids[128]; + char method[16]; +} *LP_swapstats; + +struct LP_swapstats *LP_swapstats_find(uint64_t aliceid) +{ + struct LP_swapstats *sp; + HASH_FIND(hh,LP_swapstats,&aliceid,sizeof(aliceid),sp); + return(sp); +} + +struct LP_swapstats *LP_swapstats_add(uint64_t aliceid) +{ + struct LP_swapstats *sp; + if ( (sp= LP_swapstats_find(aliceid)) == 0 ) + { + sp = calloc(1,sizeof(*sp)); + sp->aliceid = aliceid; + HASH_ADD(hh,LP_swapstats,aliceid,sizeof(aliceid),sp); + } + return(LP_swapstats_find(aliceid)); +} uint64_t LP_aliceid_calc(bits256 desttxid,int32_t destvout,bits256 feetxid,int32_t feevout) { return((((uint64_t)desttxid.uints[0] << 48) | ((uint64_t)destvout << 32) | ((uint64_t)feetxid.uints[0] << 16) | (uint32_t)feevout)); } +void LP_swapstats_line(char *line,struct LP_swapstats *sp) +{ + char tstr[64]; + printf("%s %8s %-4d %9s swap.%016llx: (%.8f %5s) -> (%.8f %5s) qprice %.8f",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,LP_aliceids,sp->method,(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice); +} + int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { - double qprice; uint32_t timestamp; int32_t i,destvout,feevout,duplicate=0; char *gui,*base,*rel,tstr[128]; uint64_t txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t aliceid; + struct LP_swapstats *sp; double qprice; uint32_t timestamp; int32_t destvout,feevout,duplicate=0; char *gui,*base,*rel,line[1024]; uint64_t txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t aliceid; memset(&Q,0,sizeof(Q)); if ( LP_quoteparse(&Q,lineobj) < 0 ) { @@ -83,20 +111,21 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) qprice = ((double)destsatoshis / (satoshis - txfee)); //printf("%s/v%d %s/v%d\n",bits256_str(str,desttxid),destvout,bits256_str(str2,feetxid),feevout); aliceid = LP_aliceid_calc(desttxid,destvout,feetxid,feevout); - for (i=0; i (%.8f %5s) qprice %.8f\n",utc_str(tstr,timestamp),gui!=0?gui:"",LP_numridqids,method,(long long)aliceid,dstr(satoshis),base,dstr(destsatoshis),rel,qprice); - LP_numridqids++; + if ( (sp= LP_swapstats_add(aliceid)) != 0 ) + { + sp->Q = Q; + sp->qprice = qprice; + LP_swapstats_line(line,sp); + printf("%s\n",line); + LP_aliceids++; + } else printf("unexpected LP_swapstats_add failure\n"); } } return(duplicate == 0); @@ -135,7 +164,7 @@ void LP_statslog_parseline(cJSON *lineobj) char *LP_statslog_disp(int32_t n) { - cJSON *retjson; + cJSON *retjson,*array; struct LP_swapstats *sp,*tmp; char line[1024]; retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jaddnum(retjson,"newlines",n); @@ -145,9 +174,16 @@ char *LP_statslog_disp(int32_t n) jaddnum(retjson,"connected",LP_connecteds); jaddnum(retjson,"duplicates",LP_duplicates); jaddnum(retjson,"parse_errors",LP_parse_errors); - jaddnum(retjson,"uniques",LP_numridqids); + jaddnum(retjson,"uniques",LP_aliceids); jaddnum(retjson,"tradestatus",LP_tradestatuses); jaddnum(retjson,"unknown",LP_unknowns); + array = cJSON_CreateArray(); + HASH_ITER(hh,LP_swapstats,sp,tmp) + { + LP_swapstats_line(line,sp); + jaddistr(array,line); + } + jadd(retjson,"swaps",array); return(jprint(retjson,1)); } From 26133c53b493b3c7b6ea274ae5eb90342012ef37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 16:57:55 +0300 Subject: [PATCH 29/63] Test --- iguana/exchanges/LP_stats.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 62125740f..700b04c26 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -46,6 +46,7 @@ struct LP_swapstats struct LP_quoteinfo Q; double qprice; uint64_t aliceid; + uint32_t ind; char method[16]; } *LP_swapstats; @@ -76,7 +77,7 @@ uint64_t LP_aliceid_calc(bits256 desttxid,int32_t destvout,bits256 feetxid,int32 void LP_swapstats_line(char *line,struct LP_swapstats *sp) { char tstr[64]; - printf("%s %8s %-4d %9s swap.%016llx: (%.8f %5s) -> (%.8f %5s) qprice %.8f",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,LP_aliceids,sp->method,(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice); + sprintf(line,"%s %8s %-4d %9s swap.%016llx: (%.8f %5s) -> (%.8f %5s) qprice %.8f",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,sp->method,(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice); } int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) @@ -122,9 +123,9 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { sp->Q = Q; sp->qprice = qprice; + sp->ind = LP_aliceids++; LP_swapstats_line(line,sp); printf("%s\n",line); - LP_aliceids++; } else printf("unexpected LP_swapstats_add failure\n"); } } From 4bca125831c5b0e8ce2c79e0b7fcca1cb600f357 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 17:27:36 +0300 Subject: [PATCH 30/63] Test --- iguana/exchanges/LP_stats.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 700b04c26..fdf875cf4 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -20,6 +20,8 @@ #define LP_STATSLOG_FNAME "stats.log" +char *LP_stats_methods[] = { "unknown", "request", "reserved", "connect", "connected", "tradestatus" }; + void LP_tradecommand_log(cJSON *argjson) { static FILE *logfp; char *jsonstr; @@ -46,8 +48,7 @@ struct LP_swapstats struct LP_quoteinfo Q; double qprice; uint64_t aliceid; - uint32_t ind; - char method[16]; + uint32_t ind,methodind; } *LP_swapstats; struct LP_swapstats *LP_swapstats_find(uint64_t aliceid) @@ -77,12 +78,17 @@ uint64_t LP_aliceid_calc(bits256 desttxid,int32_t destvout,bits256 feetxid,int32 void LP_swapstats_line(char *line,struct LP_swapstats *sp) { char tstr[64]; - sprintf(line,"%s %8s %-4d %9s swap.%016llx: (%.8f %5s) -> (%.8f %5s) qprice %.8f",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,sp->method,(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice); + sprintf(line,"%s %8s %-4d %9s swap.%016llx: (%.8f %5s) -> (%.8f %5s) qprice %.8f",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice); +} + +void LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON *lineobj) +{ + } int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { - struct LP_swapstats *sp; double qprice; uint32_t timestamp; int32_t destvout,feevout,duplicate=0; char *gui,*base,*rel,line[1024]; uint64_t txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t aliceid; + struct LP_swapstats *sp; double qprice; uint32_t timestamp; int32_t i,methodind,destvout,feevout,duplicate=0; char *gui,*base,*rel,line[1024]; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; memset(&Q,0,sizeof(Q)); if ( LP_quoteparse(&Q,lineobj) < 0 ) { @@ -92,6 +98,12 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) } else { + for (i=methodind=0; i sp->methodind || strcmp(method,"tradestatus") == 0 ) + { + sp->methodind = methodind; + LP_swapstats_update(sp,&Q,lineobj); + } duplicate = 1; LP_duplicates++; } @@ -123,6 +140,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { sp->Q = Q; sp->qprice = qprice; + sp->methodind = methodind; sp->ind = LP_aliceids++; LP_swapstats_line(line,sp); printf("%s\n",line); From 388ca5a875652d5bb549661aa395433f0a89d004 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 18:40:58 +0300 Subject: [PATCH 31/63] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_prices.c | 15 +++++++ iguana/exchanges/LP_stats.c | 78 +++++++++++++++++++++++++++++++---- 3 files changed, 85 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 01872157f..95a827003 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -290,7 +290,7 @@ struct basilisk_swap }; -#define LP_MAXPRICEINFOS 256 +#define LP_MAXPRICEINFOS 1024 struct LP_pubkeyinfo { UT_hash_handle hh; diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index fdc14779c..68125fbfa 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -47,6 +47,13 @@ struct LP_cacheinfo uint32_t timestamp; } *LP_cacheinfos; +char *LP_priceinfostr(int32_t ind) +{ + if ( ind < 0 || ind >= LP_MAXPRICEINFOS ) + return("UNKNOWN"); + else return(LP_priceinfos[ind].symbol); +} + int32_t LP_pricevalid(double price) { if ( price > SMALLVAL && isnan(price) == 0 && price < SATOSHIDEN ) @@ -70,6 +77,14 @@ struct LP_priceinfo *LP_priceinfofind(char *symbol) return(0); } +int32_t LP_priceinfoind(char *symbol) +{ + struct LP_priceinfo *pp; + if ( (pp= LP_priceinfofind(symbol)) != 0 ) + return(pp->ind); + else return(-1); +} + struct LP_priceinfo *LP_priceinfoptr(int32_t *indp,char *base,char *rel) { struct LP_priceinfo *basepp,*relpp; diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index fdf875cf4..ee53a6d22 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -46,9 +46,10 @@ struct LP_swapstats { UT_hash_handle hh; struct LP_quoteinfo Q; + bits256 bobdeposit,alicepayment,bobpayment,paymentspent,Apaymentspent,depositspent; double qprice; uint64_t aliceid; - uint32_t ind,methodind; + uint32_t ind,methodind,finished; } *LP_swapstats; struct LP_swapstats *LP_swapstats_find(uint64_t aliceid) @@ -75,20 +76,63 @@ uint64_t LP_aliceid_calc(bits256 desttxid,int32_t destvout,bits256 feetxid,int32 return((((uint64_t)desttxid.uints[0] << 48) | ((uint64_t)destvout << 32) | ((uint64_t)feetxid.uints[0] << 16) | (uint32_t)feevout)); } -void LP_swapstats_line(char *line,struct LP_swapstats *sp) +void LP_swapstats_line(uint64_t *basevols,uint64_t *relvols,char *line,struct LP_swapstats *sp) { - char tstr[64]; - sprintf(line,"%s %8s %-4d %9s swap.%016llx: (%.8f %5s) -> (%.8f %5s) qprice %.8f",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice); + char tstr[64]; int32_t baseind,relind; + if ( (baseind= LP_priceinfoind(sp->Q.srccoin)) >= 0 ) + basevols[baseind] += sp->Q.satoshis; + if ( (relind= LP_priceinfoind(sp->Q.destcoin)) >= 0 ) + relvols[relind] += sp->Q.destsatoshis; + sprintf(line,"%s %8s %-4d %9s swap.%016llx: (%.8f %5s) -> (%.8f %5s) qprice %.8f finished.%d",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished); +} + +bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) +{ + bits256 txid,deadtxid; + decode_hex(deadtxid.bytes,32,"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); + txid = jbits256(argjson,name); + if ( bits256_nonz(txid) != 0 ) + { + if ( bits256_cmp(deadtxid,txid) == 0 ) + { + if ( bits256_nonz(oldtxid) == 0 ) + return(deadtxid); + else return(oldtxid); + } else return(txid); + } else return(oldtxid); } void LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON *lineobj) { - + char *statusstr,*base,*rel; uint32_t requestid,quoteid; uint64_t satoshis,destsatoshis; + if ( strcmp(LP_stats_methods[sp->methodind],"tradestatus") == 0 ) + { + base = jstr(lineobj,"bob"); + rel = jstr(lineobj,"alice"); + requestid = juint(lineobj,"requestid"); + quoteid = juint(lineobj,"quoteid"); + satoshis = jdouble(lineobj,"srcamount") * SATOSHIDEN; + destsatoshis = jdouble(lineobj,"destamount") * SATOSHIDEN; + if ( base != 0 && strcmp(base,sp->Q.srccoin) == 0 && rel != 0 && strcmp(rel,sp->Q.destcoin) == 0 && requestid == sp->Q.R.requestid && quoteid == sp->Q.R.quoteid && satoshis == sp->Q.satoshis && destsatoshis == sp->Q.destsatoshis ) + { + sp->bobdeposit = LP_swapstats_txid(lineobj,"bobdeposit",sp->bobdeposit); + sp->alicepayment = LP_swapstats_txid(lineobj,"alicepayment",sp->alicepayment); + sp->bobpayment = LP_swapstats_txid(lineobj,"bobpayment",sp->bobpayment); + sp->paymentspent = LP_swapstats_txid(lineobj,"paymentspent",sp->paymentspent); + sp->Apaymentspent = LP_swapstats_txid(lineobj,"Apaymentspent",sp->Apaymentspent); + sp->depositspent = LP_swapstats_txid(lineobj,"depositspent",sp->depositspent); + if ( (statusstr= jstr(lineobj,"status")) != 0 && strcmp(statusstr,"finished") == 0 ) + sp->finished = juint(lineobj,"timestamp"); + } else printf("mismatched tradestatus aliceid.%016llx\n",(long long)sp->aliceid); + + } else sp->Q = *qp; } int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { - struct LP_swapstats *sp; double qprice; uint32_t timestamp; int32_t i,methodind,destvout,feevout,duplicate=0; char *gui,*base,*rel,line[1024]; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; + struct LP_swapstats *sp; double qprice; uint32_t timestamp; int32_t i,methodind,destvout,feevout,duplicate=0; char *gui,*base,*rel,line[1024]; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; + memset(basevols,0,sizeof(basevols)); + memset(relvols,0,sizeof(relvols)); memset(&Q,0,sizeof(Q)); if ( LP_quoteparse(&Q,lineobj) < 0 ) { @@ -142,7 +186,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) sp->qprice = qprice; sp->methodind = methodind; sp->ind = LP_aliceids++; - LP_swapstats_line(line,sp); + LP_swapstats_line(basevols,relvols,line,sp); printf("%s\n",line); } else printf("unexpected LP_swapstats_add failure\n"); } @@ -183,7 +227,9 @@ void LP_statslog_parseline(cJSON *lineobj) char *LP_statslog_disp(int32_t n) { - cJSON *retjson,*array; struct LP_swapstats *sp,*tmp; char line[1024]; + cJSON *retjson,*array,*item; struct LP_swapstats *sp,*tmp; int32_t i; char line[1024]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; + memset(basevols,0,sizeof(basevols)); + memset(relvols,0,sizeof(relvols)); retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jaddnum(retjson,"newlines",n); @@ -199,10 +245,24 @@ char *LP_statslog_disp(int32_t n) array = cJSON_CreateArray(); HASH_ITER(hh,LP_swapstats,sp,tmp) { - LP_swapstats_line(line,sp); + LP_swapstats_line(basevols,relvols,line,sp); jaddistr(array,line); } jadd(retjson,"swaps",array); + array = cJSON_CreateArray(); + for (i=0; i Date: Thu, 26 Oct 2017 18:49:08 +0300 Subject: [PATCH 32/63] Test --- iguana/exchanges/LP_stats.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index ee53a6d22..79a88ce3b 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -20,8 +20,20 @@ #define LP_STATSLOG_FNAME "stats.log" +struct LP_swapstats +{ + UT_hash_handle hh; + struct LP_quoteinfo Q; + bits256 bobdeposit,alicepayment,bobpayment,paymentspent,Apaymentspent,depositspent; + double qprice; + uint64_t aliceid; + uint32_t ind,methodind,finished,expired; +} *LP_swapstats; + char *LP_stats_methods[] = { "unknown", "request", "reserved", "connect", "connected", "tradestatus" }; +static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_aliceids; + void LP_tradecommand_log(cJSON *argjson) { static FILE *logfp; char *jsonstr; @@ -40,18 +52,6 @@ void LP_tradecommand_log(cJSON *argjson) } } -static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_aliceids; - -struct LP_swapstats -{ - UT_hash_handle hh; - struct LP_quoteinfo Q; - bits256 bobdeposit,alicepayment,bobpayment,paymentspent,Apaymentspent,depositspent; - double qprice; - uint64_t aliceid; - uint32_t ind,methodind,finished; -} *LP_swapstats; - struct LP_swapstats *LP_swapstats_find(uint64_t aliceid) { struct LP_swapstats *sp; @@ -83,7 +83,7 @@ void LP_swapstats_line(uint64_t *basevols,uint64_t *relvols,char *line,struct LP basevols[baseind] += sp->Q.satoshis; if ( (relind= LP_priceinfoind(sp->Q.destcoin)) >= 0 ) relvols[relind] += sp->Q.destsatoshis; - sprintf(line,"%s %8s %-4d %9s swap.%016llx: (%.8f %5s) -> (%.8f %5s) qprice %.8f finished.%d",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished); + sprintf(line,"%s %8s %-4d %9s %016llx: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired); } bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) @@ -105,6 +105,8 @@ bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) void LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON *lineobj) { char *statusstr,*base,*rel; uint32_t requestid,quoteid; uint64_t satoshis,destsatoshis; + if ( time(NULL) > sp->Q.timestamp+INSTANTDEX_LOCKTIME*2 ) + sp->expired = (uint32_t)time(NULL); if ( strcmp(LP_stats_methods[sp->methodind],"tradestatus") == 0 ) { base = jstr(lineobj,"bob"); @@ -216,7 +218,10 @@ void LP_statslog_parseline(cJSON *lineobj) LP_connecteds++; } else if ( strcmp(method,"tradestatus") == 0 ) + { + LP_statslog_parsequote(method,lineobj); LP_tradestatuses++; + } else { LP_unknowns++; From f3ebbd249b488671ab0a160a42d9e9235fe158e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 18:52:07 +0300 Subject: [PATCH 33/63] Test --- iguana/exchanges/LP_stats.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 79a88ce3b..3ad264852 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -136,7 +136,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) memset(basevols,0,sizeof(basevols)); memset(relvols,0,sizeof(relvols)); memset(&Q,0,sizeof(Q)); - if ( LP_quoteparse(&Q,lineobj) < 0 ) + if ( strcmp(method,"tradestatus") != 0 && LP_quoteparse(&Q,lineobj) < 0 ) { printf("quoteparse_error.(%s)\n",jprint(lineobj,0)); LP_parse_errors++; @@ -238,15 +238,6 @@ char *LP_statslog_disp(int32_t n) retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jaddnum(retjson,"newlines",n); - jaddnum(retjson,"request",LP_requests); - jaddnum(retjson,"reserved",LP_reserveds); - jaddnum(retjson,"connect",LP_connects); - jaddnum(retjson,"connected",LP_connecteds); - jaddnum(retjson,"duplicates",LP_duplicates); - jaddnum(retjson,"parse_errors",LP_parse_errors); - jaddnum(retjson,"uniques",LP_aliceids); - jaddnum(retjson,"tradestatus",LP_tradestatuses); - jaddnum(retjson,"unknown",LP_unknowns); array = cJSON_CreateArray(); HASH_ITER(hh,LP_swapstats,sp,tmp) { @@ -268,6 +259,15 @@ char *LP_statslog_disp(int32_t n) } } jadd(retjson,"volumes",array); + jaddnum(retjson,"request",LP_requests); + jaddnum(retjson,"reserved",LP_reserveds); + jaddnum(retjson,"connect",LP_connects); + jaddnum(retjson,"connected",LP_connecteds); + jaddnum(retjson,"duplicates",LP_duplicates); + jaddnum(retjson,"parse_errors",LP_parse_errors); + jaddnum(retjson,"uniques",LP_aliceids); + jaddnum(retjson,"tradestatus",LP_tradestatuses); + jaddnum(retjson,"unknown",LP_unknowns); return(jprint(retjson,1)); } From ab8cbfa81a633e690ccac07b805fdc62693a7da5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 18:52:19 +0300 Subject: [PATCH 34/63] Test --- iguana/exchanges/LP_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 3ad264852..d2a22f0a3 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -189,7 +189,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) sp->methodind = methodind; sp->ind = LP_aliceids++; LP_swapstats_line(basevols,relvols,line,sp); - printf("%s\n",line); + //printf("%s\n",line); } else printf("unexpected LP_swapstats_add failure\n"); } } From c0a2160cb73acbc3f3b2bc2103eaaa07a2fc15e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 18:57:15 +0300 Subject: [PATCH 35/63] Test --- iguana/exchanges/LP_stats.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index d2a22f0a3..c29c6fa45 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -136,7 +136,23 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) memset(basevols,0,sizeof(basevols)); memset(relvols,0,sizeof(relvols)); memset(&Q,0,sizeof(Q)); - if ( strcmp(method,"tradestatus") != 0 && LP_quoteparse(&Q,lineobj) < 0 ) + for (i=methodind=0; imethodind = methodind; + LP_swapstats_update(sp,&Q,lineobj); + } else printf("unexpected tradestatus.(%s)\n",jprint(lineobj,0)); + return(0); + } + if ( LP_quoteparse(&Q,lineobj) < 0 ) { printf("quoteparse_error.(%s)\n",jprint(lineobj,0)); LP_parse_errors++; @@ -144,12 +160,6 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) } else { - for (i=methodind=0; i sp->methodind || strcmp(method,"tradestatus") == 0 ) + if ( methodind > sp->methodind ) { sp->methodind = methodind; LP_swapstats_update(sp,&Q,lineobj); From 50d253a08f504818b1ed2f2dd85fc3e533df24b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 18:59:40 +0300 Subject: [PATCH 36/63] Test --- iguana/exchanges/LP_signatures.c | 9 +++++++-- iguana/exchanges/LP_statemachine.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index a53c1ef6e..7a94a08c6 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -271,10 +271,11 @@ bits256 LP_utxos_sighash(uint32_t timestamp,uint8_t *pubsecp,bits256 pubkey,bits int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits256 pubkey,bits256 utxoshash) { - static void *ctx; int32_t retval=-1; uint8_t pub33[33],pubsecp[33],sig[65]; bits256 sighash; char str[65]; + static void *ctx; int32_t retval=-1; uint8_t pub33[33],pubsecp[33],sig[65]; bits256 sighash; char str[65]; struct LP_pubkeyinfo *pubp; if ( ctx == 0 ) ctx = bitcoin_ctx(); - if ( sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) + pubp = LP_pubkeyfind(pubkey); + if ( pubp->numerrors < LP_MAXPUBKEY_ERRORS && sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) { decode_hex(sig,65,sigstr); decode_hex(pubsecp,33,pubsecpstr); @@ -284,7 +285,11 @@ int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 { static uint32_t counter; if ( counter++ < 100 ) + { + if ( pubp != 0 ) + pubp->numerrors++; printf("LP_utxos_sigcheck failure, probably from %s with older version\n",bits256_str(str,pubkey)); + } retval = -1; } else retval = 0; } diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index b84c79843..61396e280 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -2305,7 +2305,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, { numrestraints++; butxo->T.bestflag = 0; - pubp->numerrors = 0; + //pubp->numerrors = 0; } } } From 237209fbaa1ff0004ba97beab2c64b43f759e9f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 19:06:22 +0300 Subject: [PATCH 37/63] Test --- iguana/exchanges/LP_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index c29c6fa45..9137b0c44 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -125,7 +125,7 @@ void LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON * sp->depositspent = LP_swapstats_txid(lineobj,"depositspent",sp->depositspent); if ( (statusstr= jstr(lineobj,"status")) != 0 && strcmp(statusstr,"finished") == 0 ) sp->finished = juint(lineobj,"timestamp"); - } else printf("mismatched tradestatus aliceid.%016llx\n",(long long)sp->aliceid); + } else printf("mismatched tradestatus aliceid.%016llx b%s/%s r%s/%s r%u/%u q%u/%u %.8f/%.8f -> %.8f/%.8f\n",(long long)sp->aliceid,base,sp->Q.srccoin,rel,sp->Q.destcoin,requestid,sp->Q.R.requestid,quoteid,sp->Q.R.quoteid,dstr(satoshis),dstr(sp->Q.satoshis),dstr(destsatoshis),dstr(sp->Q.destsatoshis)); } else sp->Q = *qp; } From 552833943d67afd0401d361ece50618a9ab4d938 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 19:33:50 +0300 Subject: [PATCH 38/63] Test --- iguana/exchanges/LP_commands.c | 4 ++-- iguana/exchanges/LP_signatures.c | 4 ++-- iguana/exchanges/LP_stats.c | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 32c84a180..32c30f0e0 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -106,7 +106,7 @@ enable(coin)\n\ disable(coin)\n\ notarizations(coin)\n\ parselog()\n\ -statsdisp()\n\ +statsdisp(starttime=0, endtime=0)\n\ getrawtransaction(coin, txid)\n\ inventory(coin)\n\ bestfit(rel, relvolume)\n\ @@ -220,7 +220,7 @@ stop()\n\ else if ( strcmp(method,"parselog") == 0 ) return(LP_statslog_parse()); else if ( strcmp(method,"statsdisp") == 0 ) - return(LP_statslog_disp(0)); + return(LP_statslog_disp(0,juint(argjson,"starttime"),juint(argjson,"endtime"))); else if ( strcmp(method,"secretaddresses") == 0 ) { uint8_t taddr,pubtype; diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 7a94a08c6..5cca3f372 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -275,7 +275,7 @@ int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 if ( ctx == 0 ) ctx = bitcoin_ctx(); pubp = LP_pubkeyfind(pubkey); - if ( pubp->numerrors < LP_MAXPUBKEY_ERRORS && sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) + if ( (pubp == 0|| pubp->numerrors < LP_MAXPUBKEY_ERRORS) && sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) { decode_hex(sig,65,sigstr); decode_hex(pubsecp,33,pubsecpstr); @@ -288,7 +288,7 @@ int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 { if ( pubp != 0 ) pubp->numerrors++; - printf("LP_utxos_sigcheck failure, probably from %s with older version\n",bits256_str(str,pubkey)); + printf("LP_utxos_sigcheck failure.%d, probably from %s with older version\n",pubp!=0?pubp->numerrors:-1,bits256_str(str,pubkey)); } retval = -1; } else retval = 0; diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 9137b0c44..f1f6703b4 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -240,9 +240,11 @@ void LP_statslog_parseline(cJSON *lineobj) } else printf("parseline no method.(%s)\n",jprint(lineobj,0)); } -char *LP_statslog_disp(int32_t n) +char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) { cJSON *retjson,*array,*item; struct LP_swapstats *sp,*tmp; int32_t i; char line[1024]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; + if ( starttime > endtime ) + starttime = endtime; memset(basevols,0,sizeof(basevols)); memset(relvols,0,sizeof(relvols)); retjson = cJSON_CreateObject(); @@ -251,6 +253,7 @@ char *LP_statslog_disp(int32_t n) array = cJSON_CreateArray(); HASH_ITER(hh,LP_swapstats,sp,tmp) { + if ( (starttime == 0 && endtime == 0) || (sp->Q.timestamp >= starttime && sp->Q.timestamp <= endtime) ) LP_swapstats_line(basevols,relvols,line,sp); jaddistr(array,line); } From d25dfd5b5e67f062a945f1153267000f27cefee0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 19:34:25 +0300 Subject: [PATCH 39/63] Test --- iguana/exchanges/statsdisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/statsdisp b/iguana/exchanges/statsdisp index d322235a2..768c4e8b2 100755 --- a/iguana/exchanges/statsdisp +++ b/iguana/exchanges/statsdisp @@ -1,3 +1,3 @@ #!/bin/bash source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"statsdisp\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"statsdisp\",\"starttime\":0,\"endtime\":0}" From db5dfd05f239ef1709ec5e94e9ba33c956a46ec5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 19:39:25 +0300 Subject: [PATCH 40/63] Test --- iguana/exchanges/LP_stats.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index f1f6703b4..cbef208b4 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -115,7 +115,7 @@ void LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON * quoteid = juint(lineobj,"quoteid"); satoshis = jdouble(lineobj,"srcamount") * SATOSHIDEN; destsatoshis = jdouble(lineobj,"destamount") * SATOSHIDEN; - if ( base != 0 && strcmp(base,sp->Q.srccoin) == 0 && rel != 0 && strcmp(rel,sp->Q.destcoin) == 0 && requestid == sp->Q.R.requestid && quoteid == sp->Q.R.quoteid && satoshis == sp->Q.satoshis && destsatoshis == sp->Q.destsatoshis ) + if ( base != 0 && strcmp(base,sp->Q.srccoin) == 0 && rel != 0 && strcmp(rel,sp->Q.destcoin) == 0 && requestid == sp->Q.R.requestid && quoteid == sp->Q.R.quoteid && satoshis+2*sp->Q.txfee == sp->Q.satoshis && destsatoshis+2*sp->Q.desttxfee == sp->Q.destsatoshis ) { sp->bobdeposit = LP_swapstats_txid(lineobj,"bobdeposit",sp->bobdeposit); sp->alicepayment = LP_swapstats_txid(lineobj,"alicepayment",sp->alicepayment); @@ -125,13 +125,14 @@ void LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON * sp->depositspent = LP_swapstats_txid(lineobj,"depositspent",sp->depositspent); if ( (statusstr= jstr(lineobj,"status")) != 0 && strcmp(statusstr,"finished") == 0 ) sp->finished = juint(lineobj,"timestamp"); - } else printf("mismatched tradestatus aliceid.%016llx b%s/%s r%s/%s r%u/%u q%u/%u %.8f/%.8f -> %.8f/%.8f\n",(long long)sp->aliceid,base,sp->Q.srccoin,rel,sp->Q.destcoin,requestid,sp->Q.R.requestid,quoteid,sp->Q.R.quoteid,dstr(satoshis),dstr(sp->Q.satoshis),dstr(destsatoshis),dstr(sp->Q.destsatoshis)); + } else printf("mismatched tradestatus aliceid.%016llx b%s/%s r%s/%s r%u/%u q%u/%u %.8f/%.8f -> %.8f/%.8f\n",(long long)sp->aliceid,base,sp->Q.srccoin,rel,sp->Q.destcoin,requestid,sp->Q.R.requestid,quoteid,sp->Q.R.quoteid,dstr(satoshis+2*sp->Q.txfee),dstr(sp->Q.satoshis),dstr(destsatoshis+2*sp->Q.desttxfee),dstr(sp->Q.destsatoshis)); } else sp->Q = *qp; } int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { + static uint32_t unexpected; struct LP_swapstats *sp; double qprice; uint32_t timestamp; int32_t i,methodind,destvout,feevout,duplicate=0; char *gui,*base,*rel,line[1024]; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; memset(basevols,0,sizeof(basevols)); memset(relvols,0,sizeof(relvols)); @@ -149,7 +150,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { sp->methodind = methodind; LP_swapstats_update(sp,&Q,lineobj); - } else printf("unexpected tradestatus.(%s)\n",jprint(lineobj,0)); + } else printf("unexpected.%d tradestatus.(%s)\n",unexpected++,jprint(lineobj,0)); return(0); } if ( LP_quoteparse(&Q,lineobj) < 0 ) @@ -313,7 +314,7 @@ char *LP_statslog_parse() } fclose(fp); } - return(LP_statslog_disp(n)); + return(LP_statslog_disp(n,0,0)); } From ece4ac2b99174e452d0f21bde0f15850b8a992c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 19:45:52 +0300 Subject: [PATCH 41/63] Test --- iguana/exchanges/LP_stats.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index cbef208b4..b2f8b9b0a 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -76,13 +76,13 @@ uint64_t LP_aliceid_calc(bits256 desttxid,int32_t destvout,bits256 feetxid,int32 return((((uint64_t)desttxid.uints[0] << 48) | ((uint64_t)destvout << 32) | ((uint64_t)feetxid.uints[0] << 16) | (uint32_t)feevout)); } -void LP_swapstats_line(uint64_t *basevols,uint64_t *relvols,char *line,struct LP_swapstats *sp) +void LP_swapstats_line(int32_t *numtrades,uint64_t *basevols,uint64_t *relvols,char *line,struct LP_swapstats *sp) { char tstr[64]; int32_t baseind,relind; if ( (baseind= LP_priceinfoind(sp->Q.srccoin)) >= 0 ) - basevols[baseind] += sp->Q.satoshis; + basevols[baseind] += sp->Q.satoshis, numtrades[baseind]++; if ( (relind= LP_priceinfoind(sp->Q.destcoin)) >= 0 ) - relvols[relind] += sp->Q.destsatoshis; + relvols[relind] += sp->Q.destsatoshis, numtrades[relind]++; sprintf(line,"%s %8s %-4d %9s %016llx: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired); } @@ -133,7 +133,8 @@ void LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON * int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { static uint32_t unexpected; - struct LP_swapstats *sp; double qprice; uint32_t timestamp; int32_t i,methodind,destvout,feevout,duplicate=0; char *gui,*base,*rel,line[1024]; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; + struct LP_swapstats *sp; double qprice; uint32_t timestamp; int32_t i,numtrades[LP_MAXPRICEINFOS],methodind,destvout,feevout,duplicate=0; char *gui,*base,*rel,line[1024]; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; + memset(numtrades,0,sizeof(numtrades)); memset(basevols,0,sizeof(basevols)); memset(relvols,0,sizeof(relvols)); memset(&Q,0,sizeof(Q)); @@ -199,7 +200,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) sp->qprice = qprice; sp->methodind = methodind; sp->ind = LP_aliceids++; - LP_swapstats_line(basevols,relvols,line,sp); + LP_swapstats_line(numtrades,basevols,relvols,line,sp); //printf("%s\n",line); } else printf("unexpected LP_swapstats_add failure\n"); } @@ -243,11 +244,12 @@ void LP_statslog_parseline(cJSON *lineobj) char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) { - cJSON *retjson,*array,*item; struct LP_swapstats *sp,*tmp; int32_t i; char line[1024]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; + cJSON *retjson,*array,*item; struct LP_swapstats *sp,*tmp; int32_t i,numtrades[LP_MAXPRICEINFOS]; char line[1024]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; if ( starttime > endtime ) starttime = endtime; memset(basevols,0,sizeof(basevols)); memset(relvols,0,sizeof(relvols)); + memset(numtrades,0,sizeof(numtrades)); retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jaddnum(retjson,"newlines",n); @@ -255,7 +257,7 @@ char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) HASH_ITER(hh,LP_swapstats,sp,tmp) { if ( (starttime == 0 && endtime == 0) || (sp->Q.timestamp >= starttime && sp->Q.timestamp <= endtime) ) - LP_swapstats_line(basevols,relvols,line,sp); + LP_swapstats_line(numtrades,basevols,relvols,line,sp); jaddistr(array,line); } jadd(retjson,"swaps",array); @@ -268,6 +270,7 @@ char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) jaddstr(item,"coin",LP_priceinfostr(i)); jaddnum(item,"srcvol",dstr(basevols[i])); jaddnum(item,"destvol",dstr(relvols[i])); + jaddnum(item,"numtrades",numtrades[i]); jaddnum(item,"total",dstr(basevols[i] + relvols[i])); jaddi(array,item); } From 954b6b09872e4024f70e9f0ca0eef15416060a11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 20:01:18 +0300 Subject: [PATCH 42/63] Test --- iguana/exchanges/LP_bitcoin.c | 2 +- iguana/exchanges/LP_stats.c | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 3ab402856..fb8e1f69e 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2031,7 +2031,7 @@ int32_t bitcoin_addr2rmd160(uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20], } for (i=0; imethodind = methodind; LP_swapstats_update(sp,&Q,lineobj); - } else printf("unexpected.%d tradestatus.(%s)\n",unexpected++,jprint(lineobj,0)); + } + else + { + HASH_ITER(hh,LP_swapstats,sp,tmp) + { + if ( sp->Q.R.requestid == requestid && sp->Q.R.quoteid == quoteid ) + { + sp->methodind = methodind; + LP_swapstats_update(sp,&Q,lineobj); + flag = 1; + break; + } + } + } + if ( flag == 0 ) + printf("unexpected.%d tradestatus.(%s)\n",unexpected++,jprint(lineobj,0)); return(0); } if ( LP_quoteparse(&Q,lineobj) < 0 ) From 4c9c2b23d7e904a19cf33b12b911e6f9c7cfbb8d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 20:06:19 +0300 Subject: [PATCH 43/63] Test --- iguana/exchanges/LP_stats.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 7fe012647..1e3b1879d 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -102,7 +102,7 @@ bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) } else return(oldtxid); } -void LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON *lineobj) +int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON *lineobj) { char *statusstr,*base,*rel; uint32_t requestid,quoteid; uint64_t satoshis,destsatoshis; if ( time(NULL) > sp->Q.timestamp+INSTANTDEX_LOCKTIME*2 ) @@ -125,9 +125,16 @@ void LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON * sp->depositspent = LP_swapstats_txid(lineobj,"depositspent",sp->depositspent); if ( (statusstr= jstr(lineobj,"status")) != 0 && strcmp(statusstr,"finished") == 0 ) sp->finished = juint(lineobj,"timestamp"); - } else printf("mismatched tradestatus aliceid.%016llx b%s/%s r%s/%s r%u/%u q%u/%u %.8f/%.8f -> %.8f/%.8f\n",(long long)sp->aliceid,base,sp->Q.srccoin,rel,sp->Q.destcoin,requestid,sp->Q.R.requestid,quoteid,sp->Q.R.quoteid,dstr(satoshis+2*sp->Q.txfee),dstr(sp->Q.satoshis),dstr(destsatoshis+2*sp->Q.desttxfee),dstr(sp->Q.destsatoshis)); + return(0); + } + else + { + printf("mismatched tradestatus aliceid.%016llx b%s/%s r%s/%s r%u/%u q%u/%u %.8f/%.8f -> %.8f/%.8f\n",(long long)sp->aliceid,base,sp->Q.srccoin,rel,sp->Q.destcoin,requestid,sp->Q.R.requestid,quoteid,sp->Q.R.quoteid,dstr(satoshis+2*sp->Q.txfee),dstr(sp->Q.satoshis),dstr(destsatoshis+2*sp->Q.desttxfee),dstr(sp->Q.destsatoshis)); + return(-1); + } } else sp->Q = *qp; + return(0); } int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) @@ -154,9 +161,10 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { flag = 1; sp->methodind = methodind; - LP_swapstats_update(sp,&Q,lineobj); + if ( LP_swapstats_update(sp,&Q,lineobj) == 0 ) + flag = 1; } - else + if ( flag == 0 ) { HASH_ITER(hh,LP_swapstats,sp,tmp) { From 7520c9254282f7a8bd6728393228032ceb60d499 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 20:16:32 +0300 Subject: [PATCH 44/63] Test --- iguana/exchanges/LP_stats.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 1e3b1879d..18ba31fbf 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -105,8 +105,6 @@ bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON *lineobj) { char *statusstr,*base,*rel; uint32_t requestid,quoteid; uint64_t satoshis,destsatoshis; - if ( time(NULL) > sp->Q.timestamp+INSTANTDEX_LOCKTIME*2 ) - sp->expired = (uint32_t)time(NULL); if ( strcmp(LP_stats_methods[sp->methodind],"tradestatus") == 0 ) { base = jstr(lineobj,"bob"); @@ -125,6 +123,8 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO sp->depositspent = LP_swapstats_txid(lineobj,"depositspent",sp->depositspent); if ( (statusstr= jstr(lineobj,"status")) != 0 && strcmp(statusstr,"finished") == 0 ) sp->finished = juint(lineobj,"timestamp"); + if ( sp->finished == 0 && time(NULL) > sp->Q.timestamp+INSTANTDEX_LOCKTIME*2 ) + sp->expired = (uint32_t)time(NULL); return(0); } else @@ -171,8 +171,9 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) if ( sp->Q.R.requestid == requestid && sp->Q.R.quoteid == quoteid ) { sp->methodind = methodind; - LP_swapstats_update(sp,&Q,lineobj); - flag = 1; + if ( LP_swapstats_update(sp,&Q,lineobj) == 0 ) + flag = 1; + else printf("error after delayed match\n"); break; } } @@ -271,7 +272,7 @@ void LP_statslog_parseline(cJSON *lineobj) char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) { - cJSON *retjson,*array,*item; struct LP_swapstats *sp,*tmp; int32_t i,numtrades[LP_MAXPRICEINFOS]; char line[1024]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; + cJSON *retjson,*array,*item; struct LP_swapstats *sp,*tmp; int32_t i,dispflag,numtrades[LP_MAXPRICEINFOS]; char line[1024]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; if ( starttime > endtime ) starttime = endtime; memset(basevols,0,sizeof(basevols)); @@ -283,8 +284,17 @@ char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) array = cJSON_CreateArray(); HASH_ITER(hh,LP_swapstats,sp,tmp) { - if ( (starttime == 0 && endtime == 0) || (sp->Q.timestamp >= starttime && sp->Q.timestamp <= endtime) ) - LP_swapstats_line(numtrades,basevols,relvols,line,sp); + if ( sp->finished == 0 && time(NULL) > sp->Q.timestamp+INSTANTDEX_LOCKTIME*2 ) + sp->expired = (uint32_t)time(NULL); + dispflag = 0; + if ( starttime == 0 && endtime == 0 ) + dispflag = 1; + else if ( starttime > time(NULL) && endtime == starttime && sp->finished == 0 && sp->expired == 0 ) + dispflag = 1; + else if ( sp->Q.timestamp >= starttime && sp->Q.timestamp <= endtime ) + dispflag = 1; + if ( dispflag != 0 ) + LP_swapstats_line(numtrades,basevols,relvols,line,sp); jaddistr(array,line); } jadd(retjson,"swaps",array); From 5ab884ce7877bde79d51021fe8bbbd0d77db3a85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 20:24:51 +0300 Subject: [PATCH 45/63] Test --- iguana/exchanges/LP_signatures.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 5cca3f372..efbfa6438 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -275,7 +275,7 @@ int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 if ( ctx == 0 ) ctx = bitcoin_ctx(); pubp = LP_pubkeyfind(pubkey); - if ( (pubp == 0|| pubp->numerrors < LP_MAXPUBKEY_ERRORS) && sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) + if ( (pubp == 0 || pubp->numerrors < LP_MAXPUBKEY_ERRORS) && sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) { decode_hex(sig,65,sigstr); decode_hex(pubsecp,33,pubsecpstr); @@ -355,7 +355,11 @@ struct LP_utxos_qitem { struct queueitem DL; cJSON *argjson; }; char *LP_postutxos_recv(cJSON *argjson) { - struct LP_utxos_qitem *uitem; struct iguana_info *coin; char *coinaddr,*symbol; bits256 utxoshash; cJSON *obj; + struct LP_utxos_qitem *uitem; struct iguana_info *coin; char *coinaddr,*symbol; bits256 utxoshash,pubkey; cJSON *obj; struct LP_pubkeyinfo *pubp; + pubkey = jbits256(argjson,"pubkey"); + pubp = LP_pubkeyfind(pubkey); + if ( pubp->numerrors > LP_MAXPUBKEY_ERRORS ) + return(clonestr("{\"error\":\"blacklisted\"}")); if ( (coinaddr= jstr(argjson,"coinaddr")) != 0 && (symbol= jstr(argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) { if ( strcmp(coinaddr,coin->smartaddr) == 0 ) @@ -368,7 +372,7 @@ char *LP_postutxos_recv(cJSON *argjson) { utxoshash = LP_utxoshash_calc(obj); //char str[65]; printf("got utxoshash %s\n",bits256_str(str,utxoshash)); - if ( LP_utxos_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),jbits256(argjson,"pubkey"),utxoshash) == 0 ) + if ( LP_utxos_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),pubkey,utxoshash) == 0 ) { uitem = calloc(1,sizeof(*uitem)); uitem->argjson = jduplicate(argjson); @@ -404,10 +408,11 @@ int32_t LP_utxosQ_process() int32_t LP_price_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits256 pubkey,char *base,char *rel,uint64_t price64) { - static void *ctx; int32_t retval=-1; uint8_t pub33[33],pubsecp[33],sig[65]; bits256 sighash; + static void *ctx; int32_t retval=-1; uint8_t pub33[33],pubsecp[33],sig[65]; bits256 sighash; struct LP_pubkeyinfo *pubp; if ( ctx == 0 ) ctx = bitcoin_ctx(); - if ( sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) + pubp = LP_pubkeyfind(pubkey); + if ( (pubp == 0 || pubp->numerrors < LP_MAXPUBKEY_ERRORS) && sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) { decode_hex(sig,65,sigstr); decode_hex(pubsecp,33,pubsecpstr); @@ -415,6 +420,8 @@ int32_t LP_price_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 retval = bitcoin_recoververify(ctx,"price",sig,sighash,pub33,0); if ( memcmp(pub33,pubsecp,33) != 0 || retval != 0 ) { + if ( pubp != 0 ) + pubp->numerrors++; printf("LP_price_sigcheck failure\n"); retval = -1; } @@ -525,7 +532,7 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr); retval = 0; pubp->timestamp = (uint32_t)time(NULL); - } //else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr); + } else pubp->numerrors++; } } else @@ -627,7 +634,7 @@ char *LP_uitem_recv(cJSON *argjson) { //char str[65]; printf("uitem %s %s %s/v%d %.8f ht.%d\n",symbol,coinaddr,bits256_str(str,txid),vout,dstr(value),height); if ( strcmp(coin->smartaddr,coinaddr) != 0 ) - LP_address_utxoadd("LP_uitem,recv",coin,coinaddr,txid,vout,value,height,-1); + LP_address_utxoadd("LP_uitem_recv",coin,coinaddr,txid,vout,value,height,-1); //else printf("ignore external uitem %s %s\n",symbol,coin->smartaddr); } return(clonestr("{\"result\":\"success\"}")); From ca35f1aeff9548300744f2035433ec36d25f31b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 20:29:34 +0300 Subject: [PATCH 46/63] Test --- iguana/exchanges/LP_stats.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 18ba31fbf..29fa64b7f 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -294,8 +294,10 @@ char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) else if ( sp->Q.timestamp >= starttime && sp->Q.timestamp <= endtime ) dispflag = 1; if ( dispflag != 0 ) + { LP_swapstats_line(numtrades,basevols,relvols,line,sp); - jaddistr(array,line); + jaddistr(array,line); + } } jadd(retjson,"swaps",array); array = cJSON_CreateArray(); From 098e6a1a2312c81c485cc00cbec9deb064118fc0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 20:33:49 +0300 Subject: [PATCH 47/63] Test --- iguana/exchanges/LP_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 29fa64b7f..93d848191 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -83,7 +83,7 @@ void LP_swapstats_line(int32_t *numtrades,uint64_t *basevols,uint64_t *relvols,c basevols[baseind] += sp->Q.satoshis, numtrades[baseind]++; if ( (relind= LP_priceinfoind(sp->Q.destcoin)) >= 0 ) relvols[relind] += sp->Q.destsatoshis, numtrades[relind]++; - sprintf(line,"%s %8s %-4d %9s %016llx: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired); + sprintf(line,"%s %8s %-4d %9s %016llx: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u %s",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired,LP_stats_methods[sp->methodind]); } bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) From f942cee980982c2699b46e6db4b4135b7d332182 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 20:45:20 +0300 Subject: [PATCH 48/63] Test --- iguana/exchanges/LP_stats.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 93d848191..0c88512cc 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -83,7 +83,7 @@ void LP_swapstats_line(int32_t *numtrades,uint64_t *basevols,uint64_t *relvols,c basevols[baseind] += sp->Q.satoshis, numtrades[baseind]++; if ( (relind= LP_priceinfoind(sp->Q.destcoin)) >= 0 ) relvols[relind] += sp->Q.destsatoshis, numtrades[relind]++; - sprintf(line,"%s %8s %-4d %9s %016llx: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u %s",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired,LP_stats_methods[sp->methodind]); + sprintf(line,"%s %8s %-4d %9s %016llx: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired); } bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) @@ -296,7 +296,12 @@ char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) if ( dispflag != 0 ) { LP_swapstats_line(numtrades,basevols,relvols,line,sp); - jaddistr(array,line); + item = cJSON_CreateObject(); + jadd64bits(item,"aliceid",sp->aliceid); + jaddnum(item,"requestid",sp->Q.R.requestid); + jaddnum(item,"quoteid",sp->Q.R.quoteid); + jaddstr(item,"line",line); + jaddi(array,item); } } jadd(retjson,"swaps",array); From bbb5e233ab818c5ad1392a185cbe1b4aa298bea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 20:47:32 +0300 Subject: [PATCH 49/63] Test --- iguana/exchanges/LP_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 0c88512cc..7773fb757 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -83,7 +83,7 @@ void LP_swapstats_line(int32_t *numtrades,uint64_t *basevols,uint64_t *relvols,c basevols[baseind] += sp->Q.satoshis, numtrades[baseind]++; if ( (relind= LP_priceinfoind(sp->Q.destcoin)) >= 0 ) relvols[relind] += sp->Q.destsatoshis, numtrades[relind]++; - sprintf(line,"%s %8s %-4d %9s %016llx: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired); + sprintf(line,"%s %8s %-4d %9s %22llu: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired); } bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) From fec6d2799616bce1d9c4405033524bc0a1e07971 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 20:53:47 +0300 Subject: [PATCH 50/63] Test --- iguana/exchanges/LP_stats.c | 7 +++++++ iguana/exchanges/pendings | 3 +++ 2 files changed, 10 insertions(+) create mode 100755 iguana/exchanges/pendings diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 7773fb757..8fb5af5f9 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -298,6 +298,13 @@ char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) LP_swapstats_line(numtrades,basevols,relvols,line,sp); item = cJSON_CreateObject(); jadd64bits(item,"aliceid",sp->aliceid); + jaddbits256(item,"src",sp->Q.srchash); + jaddstr(item,"base",sp->Q.srccoin); + jaddnum(item,"basevol",dstr(sp->Q.satoshis)); + jaddbits256(item,"dest",sp->Q.desthash); + jaddstr(item,"rel",sp->Q.destcoin); + jaddnum(item,"relvol",dstr(sp->Q.destsatoshis)); + jaddnum(item,"price",sp->qprice); jaddnum(item,"requestid",sp->Q.R.requestid); jaddnum(item,"quoteid",sp->Q.R.quoteid); jaddstr(item,"line",line); diff --git a/iguana/exchanges/pendings b/iguana/exchanges/pendings new file mode 100755 index 000000000..a2aa46c83 --- /dev/null +++ b/iguana/exchanges/pendings @@ -0,0 +1,3 @@ +#!/bin/bash +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"statsdisp\",\"starttime\":2000000000,\"endtime\":2000000000}" From 13cb45b249fd5a5dbbe2ab2ab2cf95e757ecde3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 20:59:19 +0300 Subject: [PATCH 51/63] Test --- iguana/exchanges/LP_commands.c | 10 ++- iguana/exchanges/LP_stats.c | 133 +++++++++++++++++---------------- 2 files changed, 75 insertions(+), 68 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 32c30f0e0..c632adbb6 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -218,9 +218,15 @@ stop()\n\ return(LP_portfolio()); } else if ( strcmp(method,"parselog") == 0 ) - return(LP_statslog_parse()); + { + int32_t n = LP_statslog_parse(); + return(LP_statslog_disp(n,2000000000,2000000000)); + } else if ( strcmp(method,"statsdisp") == 0 ) - return(LP_statslog_disp(0,juint(argjson,"starttime"),juint(argjson,"endtime"))); + { + int32_t n = LP_statslog_parse(); + return(LP_statslog_disp(n,juint(argjson,"starttime"),juint(argjson,"endtime"))); + } else if ( strcmp(method,"secretaddresses") == 0 ) { uint8_t taddr,pubtype; diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 8fb5af5f9..ee5c656c8 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -29,6 +29,7 @@ struct LP_swapstats uint64_t aliceid; uint32_t ind,methodind,finished,expired; } *LP_swapstats; +int32_t LP_statslog_parsequote(char *method,cJSON *lineobj); char *LP_stats_methods[] = { "unknown", "request", "reserved", "connect", "connected", "tradestatus" }; @@ -52,6 +53,72 @@ void LP_tradecommand_log(cJSON *argjson) } } +void LP_statslog_parseline(cJSON *lineobj) +{ + char *method; cJSON *obj; + if ( (method= jstr(lineobj,"method")) != 0 ) + { + if ( strcmp(method,"request") == 0 ) + LP_requests++; + else if ( strcmp(method,"reserved") == 0 ) + LP_reserveds++; + else if ( strcmp(method,"connect") == 0 ) + { + if ( (obj= jobj(lineobj,"trade")) == 0 ) + obj = lineobj; + LP_statslog_parsequote(method,obj); + LP_connects++; + } + else if ( strcmp(method,"connected") == 0 ) + { + LP_statslog_parsequote(method,lineobj); + LP_connecteds++; + } + else if ( strcmp(method,"tradestatus") == 0 ) + { + LP_statslog_parsequote(method,lineobj); + LP_tradestatuses++; + } + else + { + LP_unknowns++; + printf("parseline unknown method.(%s) (%s)\n",method,jprint(lineobj,0)); + } + } else printf("parseline no method.(%s)\n",jprint(lineobj,0)); +} + +int32_t LP_statslog_parse() +{ + static long lastpos; FILE *fp; char line[8192]; cJSON *lineobj; int32_t n = 0; + if ( (fp= fopen(LP_STATSLOG_FNAME,"rb")) != 0 ) + { + if ( lastpos > 0 ) + { + fseek(fp,0,SEEK_END); + if ( ftell(fp) > lastpos ) + fseek(fp,lastpos,SEEK_SET); + else + { + fclose(fp); + return(0); + } + } + while ( fgets(line,sizeof(line),fp) > 0 ) + { + lastpos = ftell(fp); + if ( (lineobj= cJSON_Parse(line)) != 0 ) + { + n++; + LP_statslog_parseline(lineobj); + //printf("%s\n",jprint(lineobj,0)); + free_json(lineobj); + } + } + fclose(fp); + } + return(n); +} + struct LP_swapstats *LP_swapstats_find(uint64_t aliceid) { struct LP_swapstats *sp; @@ -236,40 +303,6 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) return(duplicate == 0); } -void LP_statslog_parseline(cJSON *lineobj) -{ - char *method; cJSON *obj; - if ( (method= jstr(lineobj,"method")) != 0 ) - { - if ( strcmp(method,"request") == 0 ) - LP_requests++; - else if ( strcmp(method,"reserved") == 0 ) - LP_reserveds++; - else if ( strcmp(method,"connect") == 0 ) - { - if ( (obj= jobj(lineobj,"trade")) == 0 ) - obj = lineobj; - LP_statslog_parsequote(method,obj); - LP_connects++; - } - else if ( strcmp(method,"connected") == 0 ) - { - LP_statslog_parsequote(method,lineobj); - LP_connecteds++; - } - else if ( strcmp(method,"tradestatus") == 0 ) - { - LP_statslog_parsequote(method,lineobj); - LP_tradestatuses++; - } - else - { - LP_unknowns++; - printf("parseline unknown method.(%s) (%s)\n",method,jprint(lineobj,0)); - } - } else printf("parseline no method.(%s)\n",jprint(lineobj,0)); -} - char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) { cJSON *retjson,*array,*item; struct LP_swapstats *sp,*tmp; int32_t i,dispflag,numtrades[LP_MAXPRICEINFOS]; char line[1024]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; @@ -339,36 +372,4 @@ char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime) return(jprint(retjson,1)); } -char *LP_statslog_parse() -{ - static long lastpos; FILE *fp; char line[8192]; cJSON *lineobj; int32_t n = 0; - if ( (fp= fopen(LP_STATSLOG_FNAME,"rb")) != 0 ) - { - if ( lastpos > 0 ) - { - fseek(fp,0,SEEK_END); - if ( ftell(fp) > lastpos ) - fseek(fp,lastpos,SEEK_SET); - else - { - fclose(fp); - return(clonestr("{\"result\":\"success\",\"newlines\":0}")); - } - } - while ( fgets(line,sizeof(line),fp) > 0 ) - { - lastpos = ftell(fp); - if ( (lineobj= cJSON_Parse(line)) != 0 ) - { - n++; - LP_statslog_parseline(lineobj); - //printf("%s\n",jprint(lineobj,0)); - free_json(lineobj); - } - } - fclose(fp); - } - return(LP_statslog_disp(n,0,0)); -} - From 6d43bb444148ea09f0bdc0a76bf65649a820649d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 21:33:07 +0300 Subject: [PATCH 52/63] Test --- iguana/exchanges/LP_commands.c | 4 ++-- iguana/exchanges/LP_nativeDEX.c | 12 +++++++++++- iguana/exchanges/LP_network.c | 8 +++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index c632adbb6..f549526d9 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -97,7 +97,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r else if ( strcmp(method,"help") == 0 ) return(clonestr("{\"result\":\" \ available localhost RPC commands: \n \ -pricearray(base, rel, firsttime=0, lasttime=-1, timescale=60) -> [timestamp, avebid, aveask, highbid, lowask]\n\ +pricearray(base, rel, starttime=0, endtime=-1, timescale=60) -> [timestamp, avebid, aveask, highbid, lowask]\n\ setprice(base, rel, price)\n\ autoprice(base, rel, minprice, margin, refbase, refrel, factor, offset)*\n\ goal(coin=*, val=)\n\ @@ -259,7 +259,7 @@ stop()\n\ } else if ( strcmp(method,"pricearray") == 0 ) { - return(jprint(LP_pricearray(base,rel,juint(argjson,"firsttime"),juint(argjson,"lasttime"),jint(argjson,"timescale")),1)); + return(jprint(LP_pricearray(base,rel,juint(argjson,"starttime"),juint(argjson,"endtime"),jint(argjson,"timescale")),1)); } else if ( strcmp(method,"myprice") == 0 ) { diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 29f7ba595..d355bbb2a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -815,7 +815,7 @@ int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg) void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybusport,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson) { - char *myipaddr=0; long filesize,n; int32_t timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); + char *myipaddr=0; long filesize,n; int32_t timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],bindaddr2[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); LP_showwif = juint(argjson,"wif"); if ( passphrase == 0 || passphrase[0] == 0 ) { @@ -899,6 +899,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu pubsock = -1; nanomsg_transportname(0,subaddr,myipaddr,mypubport); nanomsg_transportname(1,bindaddr,myipaddr,mypubport); + nanomsg_transportname2(1,bindaddr2,myipaddr,mypubport+10); if ( (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) { if ( nn_bind(pubsock,bindaddr) >= 0 ) @@ -912,6 +913,15 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu if ( pubsock >= 0 ) nn_close(pubsock), pubsock = -1; } + if ( nn_bind(pubsock,bindaddr2) >= 0 ) + { + timeout = 1; + nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); + } + else + { + printf("error binding2 to (%s)\n",bindaddr2); + } } else printf("error getting pubsock %d\n",pubsock); printf(">>>>>>>>> myipaddr.%s (%s) pullsock.%d\n",myipaddr,subaddr,pubsock); LP_mypubsock = pubsock; diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 09d387f37..221d6175c 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -30,7 +30,13 @@ uint16_t Numpsocks,Psockport = MIN_PSOCK_PORT; char *nanomsg_transportname(int32_t bindflag,char *str,char *ipaddr,uint16_t port) { - sprintf(str,"ws://%s:%u",bindflag == 0 ? ipaddr : "*",port); // ws is worse + sprintf(str,"ws://%s:%u",bindflag == 0 ? ipaddr : "*",port); + return(str); +} + +char *nanomsg_transportname2(int32_t bindflag,char *str,char *ipaddr,uint16_t port) +{ + sprintf(str,"tcp://%s:%u",bindflag == 0 ? ipaddr : "*",port); return(str); } From 73a4aa89cd44cb916b98eaf4868b75f7c66b1f19 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 21:55:25 +0300 Subject: [PATCH 53/63] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 20 ++++++++------------ iguana/exchanges/LP_network.c | 21 ++++++++++++++++----- iguana/exchanges/LP_peers.c | 18 +++++++++++++++--- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 95a827003..965062623 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -325,7 +325,7 @@ int64_t LP_komodo_interest(bits256 txid,int64_t value); void LP_availableset(struct LP_utxoinfo *utxo); int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2); int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock); -uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired); +uint16_t LP_psock_get(char *connectaddr,char *connectaddr2,char *publicaddr,int32_t ispaired); //void LP_utxo_clientpublish(struct LP_utxoinfo *utxo); int32_t LP_coinbus(uint16_t coin_busport); int32_t LP_nanomsg_recvs(void *ctx); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index d355bbb2a..d29d53c86 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -815,7 +815,7 @@ int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg) void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybusport,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson) { - char *myipaddr=0; long filesize,n; int32_t timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],bindaddr2[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); + char *myipaddr=0; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],bindaddr2[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); LP_showwif = juint(argjson,"wif"); if ( passphrase == 0 || passphrase[0] == 0 ) { @@ -899,10 +899,15 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu pubsock = -1; nanomsg_transportname(0,subaddr,myipaddr,mypubport); nanomsg_transportname(1,bindaddr,myipaddr,mypubport); - nanomsg_transportname2(1,bindaddr2,myipaddr,mypubport+10); + nanomsg_transportname2(1,bindaddr2,myipaddr,mypubport); if ( (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) { + valid = 0; if ( nn_bind(pubsock,bindaddr) >= 0 ) + valid++; + if ( nn_bind(pubsock,bindaddr2) >= 0 ) + valid++; + if ( valid > 0 ) { timeout = 1; nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); @@ -913,17 +918,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu if ( pubsock >= 0 ) nn_close(pubsock), pubsock = -1; } - if ( nn_bind(pubsock,bindaddr2) >= 0 ) - { - timeout = 1; - nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); - } - else - { - printf("error binding2 to (%s)\n",bindaddr2); - } } else printf("error getting pubsock %d\n",pubsock); - printf(">>>>>>>>> myipaddr.%s (%s) pullsock.%d\n",myipaddr,subaddr,pubsock); + printf(">>>>>>>>> myipaddr.(%s %s) (%s) pullsock.%d valid.%d\n",bindaddr,bindaddr2,subaddr,pubsock,valid); LP_mypubsock = pubsock; } printf("got %s, initpeers\n",myipaddr); diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 221d6175c..f826b4750 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -36,7 +36,7 @@ char *nanomsg_transportname(int32_t bindflag,char *str,char *ipaddr,uint16_t por char *nanomsg_transportname2(int32_t bindflag,char *str,char *ipaddr,uint16_t port) { - sprintf(str,"tcp://%s:%u",bindflag == 0 ? ipaddr : "*",port); + sprintf(str,"tcp://%s:%u",bindflag == 0 ? ipaddr : "*",port+10); return(str); } @@ -660,7 +660,7 @@ char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired) return(retstr); } -uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired) +uint16_t LP_psock_get(char *connectaddr,char *connectaddr2,char *publicaddr,int32_t ispaired) { uint16_t publicport = 0; char *retstr,*addr; cJSON *retjson; struct LP_peerinfo *peer,*tmp; HASH_ITER(hh,LP_peerinfos,peer,tmp) @@ -675,6 +675,8 @@ uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired) safecopy(publicaddr,addr,128); if ( (addr= jstr(retjson,"connectaddr")) != 0 ) safecopy(connectaddr,addr,128); + if ( (addr= jstr(retjson,"connectaddr2")) != 0 ) + safecopy(connectaddr2,addr,128); if ( publicaddr[0] != 0 && connectaddr[0] != 0 ) publicport = juint(retjson,"publicport"); free_json(retjson); @@ -690,8 +692,9 @@ uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired) int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char *myipaddr,uint16_t mypullport,int32_t ispaired) { - int32_t nntype,pullsock,timeout; char bindaddr[128],connectaddr[128]; + int32_t nntype,pullsock,timeout; char bindaddr[128],bindaddr2[128],connectaddr[128],connectaddr2[128]; *mypullportp = mypullport; + connectaddr2[0] = 0; if ( ispaired == 0 ) { if ( LP_canbind != 0 ) @@ -702,6 +705,7 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char { nanomsg_transportname(0,publicaddr,myipaddr,mypullport); nanomsg_transportname(1,bindaddr,myipaddr,mypullport); + nanomsg_transportname2(1,bindaddr2,myipaddr,mypullport); } else { @@ -713,7 +717,7 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char } while ( *mypullportp == 0 ) { - if ( (*mypullportp= LP_psock_get(connectaddr,publicaddr,ispaired)) != 0 ) + if ( (*mypullportp= LP_psock_get(connectaddr,connectaddr2,publicaddr,ispaired)) != 0 ) break; sleep(10); printf("try to get publicaddr again\n"); @@ -729,7 +733,13 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char { printf("bind to %s error for %s: %s\n",connectaddr,publicaddr,nn_strerror(nn_errno())); exit(-1); - } else printf("nntype.%d NN_PAIR.%d connect to %s connectsock.%d\n",nntype,NN_PAIR,connectaddr,pullsock); + } + else + { + if ( connectaddr2[0] != 0 && nn_connect(pullsock,connectaddr2) > 0 ) + printf("%s ",connectaddr2); + printf("nntype.%d NN_PAIR.%d connect to %s connectsock.%d\n",nntype,NN_PAIR,connectaddr,pullsock); + } } else { @@ -738,6 +748,7 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char printf("bind to %s error for %s: %s\n",bindaddr,publicaddr,nn_strerror(nn_errno())); exit(-1); } + nn_bind(pullsock,bindaddr2); } timeout = 1; nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 064086a03..5f9fabe8e 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -56,7 +56,7 @@ char *LP_peers() struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char *ipaddr,uint16_t port,uint16_t pushport,uint16_t subport,int32_t numpeers,int32_t numutxos,uint32_t sessionid) { - uint32_t ipbits; int32_t pushsock,subsock,timeout; char checkip[64],pushaddr[64],subaddr[64]; struct LP_peerinfo *peer = 0; + uint32_t ipbits; int32_t valid,pushsock,subsock,timeout; char checkip[64],subaddr2[64],pushaddr[64],pushaddr2[64],subaddr[64]; struct LP_peerinfo *peer = 0; printf("addpeer (%s:%u) pushport.%u subport.%u\n",ipaddr,port,pushport,subport); #ifdef LP_STRICTPEERS if ( strncmp("5.9.253",ipaddr,strlen("5.9.253")) != 0 ) @@ -90,13 +90,19 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char if ( pushport != 0 && subport != 0 && (pushsock= nn_socket(AF_SP,NN_PUSH)) >= 0 ) { nanomsg_transportname(0,pushaddr,peer->ipaddr,pushport); + nanomsg_transportname(0,pushaddr2,peer->ipaddr,pushport); + valid = 0; if ( nn_connect(pushsock,pushaddr) >= 0 ) + valid++; + if ( nn_connect(pushsock,pushaddr2) >= 0 ) + valid++; + if ( valid > 0 ) { timeout = 1; nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); //maxsize = 2 * 1024 * 1024; //nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDBUF,&maxsize,sizeof(maxsize)); - printf("connected to push.(%s) %d\n",pushaddr,pushsock); + printf("connected to push.(%s $s) pushsock.%d valid.%d\n",pushaddr,pushsock,valid); peer->connected = (uint32_t)time(NULL); peer->pushsock = pushsock; if ( (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) @@ -105,10 +111,16 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char nn_setsockopt(subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(subsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0); nanomsg_transportname(0,subaddr,peer->ipaddr,subport); + nanomsg_transportname2(0,subaddr2,peer->ipaddr,subport); + valid = 0; if ( nn_connect(subsock,subaddr) >= 0 ) + valid++; + if ( nn_connect(subsock,subaddr2) >= 0 ) + valid++; + if ( valid > 0 ) { peer->subsock = subsock; - printf("connected to sub.(%s) %d\n",subaddr,peer->subsock); + printf("connected to sub.(%s %s) subsock.%d valid.%d\n",subaddr,subaddr2,peer->subsock,valie); } else nn_close(subsock); } } From 90ffcf8e180838ad48d46342015f0c4d43338499 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 21:56:39 +0300 Subject: [PATCH 54/63] Test --- iguana/exchanges/LP_peers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 5f9fabe8e..dfe18ac6f 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -120,7 +120,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char if ( valid > 0 ) { peer->subsock = subsock; - printf("connected to sub.(%s %s) subsock.%d valid.%d\n",subaddr,subaddr2,peer->subsock,valie); + printf("connected to sub.(%s %s) subsock.%d valid.%d\n",subaddr,subaddr2,peer->subsock,valid); } else nn_close(subsock); } } From ce0c7cea5abe9448c0b352ada39ad2bbd6b4768d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 22:00:09 +0300 Subject: [PATCH 55/63] Test --- iguana/exchanges/LP_nativeDEX.c | 5 +++-- iguana/exchanges/LP_peers.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index d29d53c86..f92770639 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -900,13 +900,14 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu nanomsg_transportname(0,subaddr,myipaddr,mypubport); nanomsg_transportname(1,bindaddr,myipaddr,mypubport); nanomsg_transportname2(1,bindaddr2,myipaddr,mypubport); + valid = 0; if ( (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) { valid = 0; if ( nn_bind(pubsock,bindaddr) >= 0 ) valid++; - if ( nn_bind(pubsock,bindaddr2) >= 0 ) - valid++; + if ( nn_bind(pubsock,bindaddr2) >= 0 ) + valid++; if ( valid > 0 ) { timeout = 1; diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index dfe18ac6f..bc69f25f7 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -102,7 +102,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); //maxsize = 2 * 1024 * 1024; //nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDBUF,&maxsize,sizeof(maxsize)); - printf("connected to push.(%s $s) pushsock.%d valid.%d\n",pushaddr,pushsock,valid); + printf("connected to push.(%s %s) pushsock.%d valid.%d\n",pushaddr,pushsock,valid); peer->connected = (uint32_t)time(NULL); peer->pushsock = pushsock; if ( (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) From 0c3545ddadd839dfced2a4fa550a15fd70ddaf26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 22:01:17 +0300 Subject: [PATCH 56/63] Test --- iguana/exchanges/LP_peers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index bc69f25f7..59ffed9bd 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -102,7 +102,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); //maxsize = 2 * 1024 * 1024; //nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDBUF,&maxsize,sizeof(maxsize)); - printf("connected to push.(%s %s) pushsock.%d valid.%d\n",pushaddr,pushsock,valid); + printf("connected to push.(%s %s) pushsock.%d valid.%d\n",pushaddr,pushaddr2,pushsock,valid); peer->connected = (uint32_t)time(NULL); peer->pushsock = pushsock; if ( (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) From 632e055659c022a24c070c5f82d48a388637abd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 22:10:32 +0300 Subject: [PATCH 57/63] Test --- iguana/exchanges/LP_network.c | 3 ++- iguana/exchanges/LP_peers.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index f826b4750..723da5980 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -748,7 +748,8 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char printf("bind to %s error for %s: %s\n",bindaddr,publicaddr,nn_strerror(nn_errno())); exit(-1); } - nn_bind(pullsock,bindaddr2); + if ( nn_bind(pullsock,bindaddr2) >= 0 ) + printf("bound to %s\n",bindaddr2); } timeout = 1; nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 59ffed9bd..87b03d2ad 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -121,13 +121,20 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char { peer->subsock = subsock; printf("connected to sub.(%s %s) subsock.%d valid.%d\n",subaddr,subaddr2,peer->subsock,valid); - } else nn_close(subsock); + } + else + { + printf("error connecting to subsock.%d (%s %s)\n",subsock,subaddr,subaddr2); + nn_close(subsock); + subsock = -1; + } } } else { nn_close(pushsock); - printf("error connecting to push.(%s)\n",pushaddr); + pushsock = -1; + printf("error connecting to push.(%s %s)\n",pushaddr,pushaddr2); } } else printf("%s pushport.%u subport.%u pushsock.%d\n",ipaddr,pushport,subport,pushsock); if ( peer->pushsock >= 0 && peer->subsock >= 0 ) From 1c1f9b99411812960947f3b4fc1ed7a31e29f437 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 22:27:07 +0300 Subject: [PATCH 58/63] Test --- iguana/exchanges/LP_stats.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index ee5c656c8..c665b5a99 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -171,7 +171,8 @@ bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON *lineobj) { - char *statusstr,*base,*rel; uint32_t requestid,quoteid; uint64_t satoshis,destsatoshis; + char *statusstr,*base,*rel,gui[64]; uint32_t requestid,quoteid; uint64_t satoshis,destsatoshis; + safecopy(gui,sp->Q.gui,sizeof(gui)); if ( strcmp(LP_stats_methods[sp->methodind],"tradestatus") == 0 ) { base = jstr(lineobj,"bob"); @@ -201,6 +202,8 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO } } else sp->Q = *qp; + if ( sp->Q.gui[0] == 0 || strcmp(sp->Q.gui,"nogui") == 0 ) + strcpy(sp->Q.gui,gui); return(0); } @@ -257,6 +260,9 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) } else { + gui = jstr(lineobj,"gui"); + if ( gui == 0 || gui[0] == 0 ) + gui = "nogui"; base = jstr(lineobj,"base"); rel = jstr(lineobj,"rel"); gui = jstr(lineobj,"gui"); From 63b0e72bf66e8876370d96d44d0cb0669e9bebb3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 22:34:28 +0300 Subject: [PATCH 59/63] Test --- iguana/exchanges/LP_stats.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index c665b5a99..040599693 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -181,7 +181,7 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO quoteid = juint(lineobj,"quoteid"); satoshis = jdouble(lineobj,"srcamount") * SATOSHIDEN; destsatoshis = jdouble(lineobj,"destamount") * SATOSHIDEN; - if ( base != 0 && strcmp(base,sp->Q.srccoin) == 0 && rel != 0 && strcmp(rel,sp->Q.destcoin) == 0 && requestid == sp->Q.R.requestid && quoteid == sp->Q.R.quoteid && satoshis+2*sp->Q.txfee == sp->Q.satoshis && destsatoshis+2*sp->Q.desttxfee == sp->Q.destsatoshis ) + if ( base != 0 && strcmp(base,sp->Q.srccoin) == 0 && rel != 0 && strcmp(rel,sp->Q.destcoin) == 0 && requestid == sp->Q.R.requestid && quoteid == sp->Q.R.quoteid && ((satoshis+2*sp->Q.txfee)|1) == (sp->Q.satoshis|1) && ((destsatoshis+2*sp->Q.desttxfee)|1) == (sp->Q.destsatoshis|1) ) { sp->bobdeposit = LP_swapstats_txid(lineobj,"bobdeposit",sp->bobdeposit); sp->alicepayment = LP_swapstats_txid(lineobj,"alicepayment",sp->alicepayment); @@ -197,7 +197,8 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO } else { - printf("mismatched tradestatus aliceid.%016llx b%s/%s r%s/%s r%u/%u q%u/%u %.8f/%.8f -> %.8f/%.8f\n",(long long)sp->aliceid,base,sp->Q.srccoin,rel,sp->Q.destcoin,requestid,sp->Q.R.requestid,quoteid,sp->Q.R.quoteid,dstr(satoshis+2*sp->Q.txfee),dstr(sp->Q.satoshis),dstr(destsatoshis+2*sp->Q.desttxfee),dstr(sp->Q.destsatoshis)); + if ( requestid == sp->Q.R.requestid && quoteid == sp->Q.R.quoteid ) + printf("mismatched tradestatus aliceid.%016llx b%s/%s r%s/%s r%u/%u q%u/%u %.8f/%.8f -> %.8f/%.8f\n",(long long)sp->aliceid,base,sp->Q.srccoin,rel,sp->Q.destcoin,requestid,sp->Q.R.requestid,quoteid,sp->Q.R.quoteid,dstr(satoshis+2*sp->Q.txfee),dstr(sp->Q.satoshis),dstr(destsatoshis+2*sp->Q.desttxfee),dstr(sp->Q.destsatoshis)); return(-1); } @@ -263,6 +264,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) gui = jstr(lineobj,"gui"); if ( gui == 0 || gui[0] == 0 ) gui = "nogui"; + printf("%s\n",gui); base = jstr(lineobj,"base"); rel = jstr(lineobj,"rel"); gui = jstr(lineobj,"gui"); From 091fec3e9c853f50df753bb39e3cb7d75f05dfe3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 22:39:09 +0300 Subject: [PATCH 60/63] Test --- iguana/exchanges/LP_stats.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 040599693..5f5068774 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -28,6 +28,7 @@ struct LP_swapstats double qprice; uint64_t aliceid; uint32_t ind,methodind,finished,expired; + char alicegui[32],bobgui[32]; } *LP_swapstats; int32_t LP_statslog_parsequote(char *method,cJSON *lineobj); @@ -150,7 +151,7 @@ void LP_swapstats_line(int32_t *numtrades,uint64_t *basevols,uint64_t *relvols,c basevols[baseind] += sp->Q.satoshis, numtrades[baseind]++; if ( (relind= LP_priceinfoind(sp->Q.destcoin)) >= 0 ) relvols[relind] += sp->Q.destsatoshis, numtrades[relind]++; - sprintf(line,"%s %8s %-4d %9s %22llu: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u",utc_str(tstr,sp->Q.timestamp),sp->Q.gui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired); + sprintf(line,"%s %8s/%8s %-4d %9s %22llu: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u",utc_str(tstr,sp->Q.timestamp),sp->alicegui,sp->bobgui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired); } bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) @@ -264,7 +265,9 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) gui = jstr(lineobj,"gui"); if ( gui == 0 || gui[0] == 0 ) gui = "nogui"; - printf("%s\n",gui); + if ( jint(lineobj,"iambob") != 0 ) + strcpy(sp->bobgui,gui); + else strcpy(sp->alicegui,gui); base = jstr(lineobj,"base"); rel = jstr(lineobj,"rel"); gui = jstr(lineobj,"gui"); From 95689b1e6b0dfa5692b1d777f37cabdd5a199401 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 22:40:29 +0300 Subject: [PATCH 61/63] Test --- iguana/exchanges/LP_stats.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 5f5068774..a4c734671 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -265,9 +265,6 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) gui = jstr(lineobj,"gui"); if ( gui == 0 || gui[0] == 0 ) gui = "nogui"; - if ( jint(lineobj,"iambob") != 0 ) - strcpy(sp->bobgui,gui); - else strcpy(sp->alicegui,gui); base = jstr(lineobj,"base"); rel = jstr(lineobj,"rel"); gui = jstr(lineobj,"gui"); @@ -310,6 +307,15 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) //printf("%s\n",line); } else printf("unexpected LP_swapstats_add failure\n"); } + if ( sp != 0 ) + { + if ( strcmp(gui,"nogui") != 0 ) + { + if ( jint(lineobj,"iambob") != 0 ) + strcpy(sp->bobgui,gui); + else strcpy(sp->alicegui,gui); + } + } } return(duplicate == 0); } From 952405aa386dd50525b96fbd7f4d0993619f7efa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 22:45:28 +0300 Subject: [PATCH 62/63] Test --- iguana/exchanges/LP_stats.c | 1 - 1 file changed, 1 deletion(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index a4c734671..9314987e5 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -267,7 +267,6 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) gui = "nogui"; base = jstr(lineobj,"base"); rel = jstr(lineobj,"rel"); - gui = jstr(lineobj,"gui"); satoshis = j64bits(lineobj,"satoshis"); if ( base == 0 || rel == 0 || satoshis == 0 ) { From 1af9908cd8d3cbb9e0676a6104fa4a9bae6b7698 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 22:48:53 +0300 Subject: [PATCH 63/63] Test --- iguana/exchanges/LP_stats.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 9314987e5..89919ef3f 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -151,7 +151,7 @@ void LP_swapstats_line(int32_t *numtrades,uint64_t *basevols,uint64_t *relvols,c basevols[baseind] += sp->Q.satoshis, numtrades[baseind]++; if ( (relind= LP_priceinfoind(sp->Q.destcoin)) >= 0 ) relvols[relind] += sp->Q.destsatoshis, numtrades[relind]++; - sprintf(line,"%s %8s/%8s %-4d %9s %22llu: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u",utc_str(tstr,sp->Q.timestamp),sp->alicegui,sp->bobgui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired); + sprintf(line,"%s (%s).(%s) %-4d %9s %22llu: (%.8f %5s) -> (%.8f %5s) %.8f finished.%u expired.%u",utc_str(tstr,sp->Q.timestamp),sp->alicegui,sp->bobgui,sp->ind,LP_stats_methods[sp->methodind],(long long)sp->aliceid,dstr(sp->Q.satoshis),sp->Q.srccoin,dstr(sp->Q.destsatoshis),sp->Q.destcoin,sp->qprice,sp->finished,sp->expired); } bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid) @@ -212,7 +212,7 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { static uint32_t unexpected; - struct LP_swapstats *sp,*tmp; double qprice; uint32_t requestid,quoteid,timestamp; int32_t i,flag,numtrades[LP_MAXPRICEINFOS],methodind,destvout,feevout,duplicate=0; char *gui,*base,*rel,line[1024]; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; + struct LP_swapstats *sp,*tmp; double qprice; uint32_t requestid,quoteid,timestamp; int32_t i,flag,numtrades[LP_MAXPRICEINFOS],methodind,destvout,feevout,duplicate=0; char *gui,*base,*rel; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; memset(numtrades,0,sizeof(numtrades)); memset(basevols,0,sizeof(basevols)); memset(relvols,0,sizeof(relvols)); @@ -302,7 +302,9 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) sp->qprice = qprice; sp->methodind = methodind; sp->ind = LP_aliceids++; - LP_swapstats_line(numtrades,basevols,relvols,line,sp); + strcpy(sp->bobgui,"nogui"); + strcpy(sp->alicegui,"nogui"); + //LP_swapstats_line(numtrades,basevols,relvols,line,sp); //printf("%s\n",line); } else printf("unexpected LP_swapstats_add failure\n"); }