Browse Source

Test

etomic
jl777 8 years ago
parent
commit
4a21f04c41
  1. 45
      iguana/exchanges/LP_commands.c
  2. 10
      iguana/exchanges/LP_forwarding.c

45
iguana/exchanges/LP_commands.c

@ -257,30 +257,41 @@ forwardhex(pubkey,hex)\n\
return(clonestr("{\"result\":\"success\",\"notifyutxo\":\"received\"}")); return(clonestr("{\"result\":\"success\",\"notifyutxo\":\"received\"}"));
else return(clonestr("{\"result\":\"couldnt add utxo\"}")); else return(clonestr("{\"result\":\"couldnt add utxo\"}"));
} }
else if ( IAMLP != 0 ) else
{ {
if ( strcmp(method,"register") == 0 ) if ( IAMLP != 0 )
{ {
retstr = LP_register(jbits256(argjson,"client"),jstr(argjson,"pushaddr"),juint(argjson,"pushport")); if ( strcmp(method,"register") == 0 )
printf("got (%s) from register\n",retstr!=0?retstr:""); {
return(retstr); retstr = LP_register(jbits256(argjson,"client"),jstr(argjson,"pushaddr"),juint(argjson,"pushport"));
printf("got (%s) from register\n",retstr!=0?retstr:"");
return(retstr);
}
else if ( strcmp(method,"lookup") == 0 )
return(LP_lookup(jbits256(argjson,"client")));
else if ( strcmp(method,"forwardhex") == 0 )
retstr = LP_forwardhex(ctx,pubsock,jbits256(argjson,"pubkey"),jstr(argjson,"hex"));
else if ( strcmp(method,"psock") == 0 )
{
if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 )
{
if ( LP_mypeer != 0 )
myipaddr = LP_mypeer->ipaddr;
else printf("LP_psock dont have actual ipaddr?\n");
}
return(LP_psock(myipaddr,jint(argjson,"ispaired")));
}
else if ( strcmp(method,"notify") == 0 )
retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}");
} }
else if ( strcmp(method,"lookup") == 0 ) else
return(LP_lookup(jbits256(argjson,"client")));
else if ( strcmp(method,"forwardhex") == 0 )
retstr = LP_forwardhex(ctx,pubsock,jbits256(argjson,"pubkey"),jstr(argjson,"hex"));
else if ( strcmp(method,"psock") == 0 )
{ {
if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 ) if ( strcmp(method,"register") == 0 )
{ {
if ( LP_mypeer != 0 ) printf("nonLP got (%s)\n",jprint(argjson,0));
myipaddr = LP_mypeer->ipaddr; retstr = clonestr("{\"result\":\"success\",\"register\":\"received\"}");
else printf("LP_psock dont have actual ipaddr?\n");
} }
return(LP_psock(myipaddr,jint(argjson,"ispaired")));
} }
else if ( strcmp(method,"notify") == 0 )
retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}");
} }
if ( retstr != 0 ) if ( retstr != 0 )
{ {

10
iguana/exchanges/LP_forwarding.c

@ -110,7 +110,7 @@ char *LP_register(bits256 pubkey,char *ipaddr,uint16_t port)
if ( ipaddr == 0 || ipaddr[0] == 0 || is_ipaddr(ipaddr) == 0 || bits256_nonz(pubkey) == 0 ) if ( ipaddr == 0 || ipaddr[0] == 0 || is_ipaddr(ipaddr) == 0 || bits256_nonz(pubkey) == 0 )
return(clonestr("{\"result\":\"illegal ipaddr or null pubkey\"}")); return(clonestr("{\"result\":\"illegal ipaddr or null pubkey\"}"));
nanomsg_transportname(0,pushaddr,ipaddr,port); nanomsg_transportname(0,pushaddr,ipaddr,port);
char str[65]; printf("register.(%s) %s\n",pushaddr,bits256_str(str,pubkey)); //char str[65]; printf("register.(%s) %s\n",pushaddr,bits256_str(str,pubkey));
if ( (ptr= LP_forwardfind(pubkey)) != 0 ) if ( (ptr= LP_forwardfind(pubkey)) != 0 )
{ {
ptr->lasttime = (uint32_t)time(NULL); ptr->lasttime = (uint32_t)time(NULL);
@ -126,13 +126,13 @@ char *LP_register(bits256 pubkey,char *ipaddr,uint16_t port)
char str[65]; printf("%u recreate pushsock for %s <- %s\n",(uint32_t)time(NULL),pushaddr,bits256_str(str,pubkey)); char str[65]; printf("%u recreate pushsock for %s <- %s\n",(uint32_t)time(NULL),pushaddr,bits256_str(str,pubkey));
strcpy(ptr->pushaddr,pushaddr); strcpy(ptr->pushaddr,pushaddr);
if ( (ptr->pushsock= LP_pushsock_create(ptr,pushaddr)) < 0 ) if ( (ptr->pushsock= LP_pushsock_create(ptr,pushaddr)) < 0 )
return(clonestr("{\"result\":\"couldnt recreate pushsock\",\"registered\":0}")); return(clonestr("{\"result\":\"success\",\"status\":\"couldnt recreate pushsock\",\"registered\":0}"));
} //else printf("no need to create identical endpoint\n"); } //else printf("no need to create identical endpoint\n");
} }
return(clonestr("{\"result\":\"already registered\",\"registered\":1}")); return(clonestr("{\"result\":\"success\",\"status\":\"already registered\",\"registered\":1}"));
} }
else if ( (pushsock= LP_pushsock_create(0,pushaddr)) < 0 ) else if ( (pushsock= LP_pushsock_create(0,pushaddr)) < 0 )
return(clonestr("{\"result\":\"couldnt create pushsock\"}")); return(clonestr("{\"result\":\"success\",\"status\":\"couldnt create pushsock\"}"));
else else
{ {
ptr = calloc(1,sizeof(*ptr)); ptr = calloc(1,sizeof(*ptr));
@ -143,7 +143,7 @@ char *LP_register(bits256 pubkey,char *ipaddr,uint16_t port)
portable_mutex_lock(&LP_forwardmutex); portable_mutex_lock(&LP_forwardmutex);
HASH_ADD_KEYPTR(hh,LP_forwardinfos,&ptr->pubkey,sizeof(ptr->pubkey),ptr); HASH_ADD_KEYPTR(hh,LP_forwardinfos,&ptr->pubkey,sizeof(ptr->pubkey),ptr);
portable_mutex_unlock(&LP_forwardmutex); portable_mutex_unlock(&LP_forwardmutex);
char str[65]; printf("registered (%s) -> (%s) pushsock.%d\n",bits256_str(str,pubkey),pushaddr,ptr->pushsock); //char str[65]; printf("registered (%s) -> (%s) pushsock.%d\n",bits256_str(str,pubkey),pushaddr,ptr->pushsock);
LP_hello(ptr); LP_hello(ptr);
return(LP_lookup(pubkey)); return(LP_lookup(pubkey));
} }

Loading…
Cancel
Save