Browse Source

Test

etomic
jl777 8 years ago
parent
commit
1d25085708
  1. 35
      iguana/exchanges/LP_forwarding.c

35
iguana/exchanges/LP_forwarding.c

@ -125,58 +125,59 @@ cJSON *LP_dereference(cJSON *argjson,char *excludemethod)
char *LP_forwardhex(int32_t pubsock,bits256 pubkey,char *hexstr) char *LP_forwardhex(int32_t pubsock,bits256 pubkey,char *hexstr)
{ {
struct LP_forwardinfo *ptr=0; uint8_t *data; int32_t datalen=0,sentbytes=0; char *retstr=0; cJSON *retjson,*argjson,*reqjson; struct LP_forwardinfo *ptr=0; uint8_t *data; int32_t datalen=0,sentbytes=0; char *retstr=0; cJSON *retjson=0,*argjson=0,*reqjson=0;
if ( hexstr == 0 || hexstr[0] == 0 ) if ( hexstr == 0 || hexstr[0] == 0 )
return(clonestr("{\"error\":\"nohex\"}")); return(clonestr("{\"error\":\"nohex\"}"));
if ( bits256_nonz(pubkey) == 0 || bits256_cmp(pubkey,LP_mypubkey) == 0 )
{
datalen = (int32_t)strlen(hexstr) >> 1; datalen = (int32_t)strlen(hexstr) >> 1;
data = malloc(datalen); data = malloc(datalen);
decode_hex(data,datalen,hexstr); decode_hex(data,datalen,hexstr);
if ( (argjson= cJSON_Parse((char *)data)) != 0 ) if ( (argjson= cJSON_Parse((char *)data)) != 0 )
{
reqjson = LP_dereference(argjson,"forward"); reqjson = LP_dereference(argjson,"forward");
if ( bits256_nonz(pubkey) == 0 || bits256_cmp(pubkey,LP_mypubkey) == 0 )
{
if ( reqjson != 0 )
{
retstr = LP_command_process(LP_mypeer != 0 ? LP_mypeer->ipaddr : "127.0.0.1",LP_mypubsock,reqjson,0,0,LP_profitratio - 1.); retstr = LP_command_process(LP_mypeer != 0 ? LP_mypeer->ipaddr : "127.0.0.1",LP_mypubsock,reqjson,0,0,LP_profitratio - 1.);
printf("LP_forwardhex.(%s) -> (%s)\n",jprint(reqjson,0),retstr!=0?retstr:""); printf("LP_forwardhex.(%s) -> (%s)\n",jprint(reqjson,0),retstr!=0?retstr:"");
if ( pubsock >= 0 ) if ( pubsock >= 0 )
LP_send(pubsock,jprint(reqjson,0),1); LP_send(pubsock,jprint(reqjson,0),0);
free_json(reqjson);
free_json(argjson);
} else printf("LP_forwardhex couldnt parse (%s)\n",(char *)data); } else printf("LP_forwardhex couldnt parse (%s)\n",(char *)data);
free(data);
return(retstr);
} }
else if ( (ptr= LP_forwardfind(pubkey)) != 0 ) else if ( (ptr= LP_forwardfind(pubkey)) != 0 )
{ {
if ( ptr->pushsock >= 0 ) if ( ptr->pushsock >= 0 )
{ {
datalen = (int32_t)strlen(hexstr) >> 1;
data = malloc(datalen);
decode_hex(data,datalen,hexstr);
printf("forwardhex.(%s)\n",(char *)data); printf("forwardhex.(%s)\n",(char *)data);
sentbytes = LP_send(ptr->pushsock,(char *)data,1); sentbytes = LP_send(ptr->pushsock,(char *)data,0);
} }
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
if ( sentbytes == datalen ) if ( sentbytes == datalen )
{ {
jaddstr(retjson,"result","success"); jaddstr(retjson,"result","success");
jaddnum(retjson,"forwarded",sentbytes); jaddnum(retjson,"forwarded",sentbytes);
return(jprint(retjson,1)); retstr = jprint(retjson,1);
} }
else else
{ {
jaddstr(retjson,"error","send error"); jaddstr(retjson,"error","send error");
jaddnum(retjson,"sentbytes",sentbytes); jaddnum(retjson,"sentbytes",sentbytes);
jaddnum(retjson,"datalen",datalen); jaddnum(retjson,"datalen",datalen);
return(jprint(retjson,1)); retstr = jprint(retjson,1);
} }
} }
else else
{ {
char str[65]; printf("couldnt find %s to forward to\n",bits256_str(str,pubkey)); char str[65]; printf("couldnt find %s to forward to\n",bits256_str(str,pubkey));
return(clonestr("{\"error\":\"notfound\"}")); if ( pubsock >= 0 )
LP_send(pubsock,jprint(reqjson,0),0);
retstr = clonestr("{\"error\":\"notfound\"}");
} }
printf("couldnt find pubkey\n"); free(data);
if ( reqjson != 0 )
free_json(reqjson);
if ( argjson != 0 )
free_json(argjson);
return(retstr);
} }
int32_t LP_forward(bits256 pubkey,char *jsonstr,int32_t freeflag) int32_t LP_forward(bits256 pubkey,char *jsonstr,int32_t freeflag)

Loading…
Cancel
Save