trex_rpc_cmd_rc_e
TrexRpcCommand::run(const Json::Value &params, Json::Value &result) {
    trex_rpc_cmd_rc_e rc;

    /* the internal run can throw a parser error / other error */
    try {

        /* verify API handler is correct (version mismatch) */
        if ( (m_api_type != APIClass::API_CLASS_TYPE_NO_API) && !g_test_override_api ) {
            verify_api_handler(params, result);
        }

        /* verify ownership */
        if (m_needs_ownership && !g_test_override_ownership) {
            verify_ownership(params, result);
        }

        check_param_count(params, m_param_count, result);

        /* run the command itself*/
        rc = _run(params, result);

    } catch (TrexRpcCommandException &e) {
        return e.get_rc();
    }

    return (rc);
}
예제 #2
0
trex_rpc_cmd_rc_e 
TrexRpcCommand::run(const Json::Value &params, Json::Value &result) {
    trex_rpc_cmd_rc_e rc;

    /* the internal run can throw a parser error / other error */
    try {

        check_param_count(params, m_param_count, result);

        if (m_needs_ownership && !g_test_override_ownership) {
            verify_ownership(params, result);
        }

        /* run the command itself*/
        rc = _run(params, result);

    } catch (TrexRpcCommandException &e) {
        return e.get_rc();
    }

    return (rc);
}
예제 #3
0
파일: logS.cpp 프로젝트: jungu/brokenseal
static ACE_THR_FUNC_RETURN
process(void* arg){
  ACE_INET_Addr addr;
  ACE_SOCK_Stream stream;
  ACE_HANDLE handle = (ACE_HANDLE) (intptr_t) arg;
  stream.set_handle(handle);
  /*make sure we're not in non-blocking mode.*/
  if(stream.disable(ACE_NONBLOCK) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
		       "%p\n",
		       "disable"),
		      0);
  }
  else if(stream.get_remote_addr(addr) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
		       "%p\n",
		       "get_remote_addr"),
		      0);
  }
  ACE_DEBUG ((LM_INFO,
	      "(%P|%t:%l) client %s connected from %d\n",
	      addr.get_host_name (),
	      addr.get_port_number ()));
  
  int r_bytes = 0;
  char buf[SIZE];
  ACE_CString cs;
  do{
    r_bytes = stream.recv(buf, SIZE);

    if(r_bytes == 0 || r_bytes == -1){
      ACE_DEBUG((LM_INFO,
		 "(%P|%t:%l) r_bytes = %d, exit from the loop\n", r_bytes));
      break;
    }
    for(int i=0; i< r_bytes; i++){
      cs += buf[i];
    }
  }while(true);
  stream.close_reader();
  /*
  ACE_DEBUG((LM_INFO,
	     "%s\n", cs.c_str()));
  */
  /*the layout of the message would be:
   * ^^pq||step1$$
   * 1st step: get the d by pq
   * 2nd calculate
   * 3rd send back the digest
   */
  int p0, p1;
  int len = cs.length();
  p0 = 2;
  p1 = cs.find("||");
  ACE_CString pq = cs.substr(2, p1 - 2);
  ACE_CString step1 = cs.substr(p1 + 2, len - p1 -4);
  /*
  ACE_DEBUG((LM_INFO,
	     "pq = %s\n step1 = %s\n", pq.c_str(), step1.c_str()));
  */
  //get the d
  ACE_CString sql = "select d,textid from player0 where pq='";
  sql += pq;
  sql += "'";
  /*
  ACE_DEBUG((LM_INFO,
	     "sql = %s\n", sql.c_str()));
*/
  PGconn* con;
  con = PQconnectdb("host=45.33.3.188 port=5432 dbname=nv user=dec");
  PGresult* res;
  if(PQstatus(con)!= CONNECTION_OK){
    ACE_DEBUG((LM_INFO,
	       "Connection to database failed:%s\n",
	       PQerrorMessage(con)));
    reclaim_conn(con);
  }
  res = PQexec(con, sql.c_str());
  int n = PQntuples(res);
  if(n != 1){
    ACE_ERROR((LM_ERROR,
	       "there is significant error: %d\n", n));
    //    return 0;
  }
  ACE_CString d = "";
  d += PQgetvalue(res, 0, 0);
  /*
  ACE_DEBUG((LM_INFO,
	     "d = %s\n", d.c_str()));
*/
  bn* pq_ = from_hex(&pq);
  bn* d_ = from_hex(&d);
  bn* step1_ = from_hex(&step1);
  bn* step2_ = npmod(step1_ , d_ , pq_ );
  ACE_CString* step2 = step2_->to_hex();
  
  //check if the pq is taking the ownnership?

  /* if pq is 'centralbank', bypass the check, otherwise check the payer whether has the ownnership of the note;
   * select count(*) from ownership0 o, player0 p where o.owner = p.textid  and o.note='0x12345678' and p.pq='0x12345678';
   */
  bn* e_ = new bn(1);
  e_->addat(0,0x10001);
  bn* step3_ = npmod(step2_ , e_ , pq_ );
  ACE_CString* rawMsg = encode(step3_);
  ACE_DEBUG((LM_INFO,
	     "%T :%l step3 = %s\n", rawMsg->c_str()));
  if(verify_ownership(rawMsg, pq)){
    //update the ownership;
    int pos1 = rawMsg->find("->");
    ACE_CString note = rawMsg->substr(2, pos1 -2);
    int rawlen = rawMsg->length();
    ACE_CString id = rawMsg->substr(pos1 + 2, rawlen - pos1 - 6);
    update_ownership(note, id);
    /*insert the log entry*/
    insert_logentry(pq, *step2, *rawMsg, note, id);
    stream.send( step2->c_str(), step2->length());
    /*
    ACE_DEBUG((LM_INFO,
	       "%T :%l the step2 message is:\n%s\n", step2->c_str()));
    */
  }else{
    ACE_DEBUG((LM_INFO,
	       "%T :%l invalid transfer\n"));
    ACE_CString reply ="invalid transfer\n";
    stream.send( reply.c_str(), reply.length());
  }
  delete step2 ;
  delete pq_;
  delete d_;
  delete step1_;
  delete step2_;
  delete e_;
  delete step3_;
  delete rawMsg;
  /*
  stream.close_writer();
  */
  stream.close();
  ACE_DEBUG((LM_INFO,
	     "%T :%l closed the stream\n"));

}