示例#1
0
build_model()
{
	int i,j,k;
	nodeptr p, p1, root1, root_sw, simp();
	char	f_name[MAX_NAME];
	char	v_name[MAX_NAME];
		
	for (i=1; i<=n_gen+m_pv+s_pq; i++)
	{
		j=n_gen+m_pv+s_pq;
		root1=f1_term(i,j,'1');	
		
		for (k=1; k<=5+n_gen+m_pv+s_pq; k++) root1=simp(root1);
		
		p=new_node();
		p->node_id='b';
		p->node_data.bi_term.oprt='-';
		p->node_data.bi_term.left=root1;
		sprintf(v_name,"p[%d]",i);
		p->node_data.bi_term.right=find_node(name_header,v_name,'c');		
		
		sprintf(f_name,"f1[%d]=", i);
		store_func(func_header, f_name, p);
			
		if (i>n_gen+m_pv) 
		{
			j=n_gen+m_pv+s_pq;	
			root1=f1_term(i,j,'2');
			for (k=1; k<=5+n_gen+m_pv+s_pq; k++) root1=simp(root1);	
			
			p=new_node();
			p->node_id='b';
			p->node_data.bi_term.oprt='-';
			p->node_data.bi_term.left=root1;
			sprintf(v_name,"q[%d]",i);
			p->node_data.bi_term.right=find_node(name_header,v_name,'c');	
			
			sprintf(f_name,"f2[%d]=", i-n_gen-m_pv);
			store_func(func_header, f_name, p);
			
		}
	}
}
示例#2
0
void TestApp::start()
{
	struct timeval tmv;
	int status;

	fd_set READ_SET;
		fd_set READ_SET_COPY;

		//outfile_client<<"inside seleact"<<endl;
		cout<<"inside select function"<<endl;
			int max_sock;

			if(UDP_private > sockfd_client)
			{
				 max_sock=UDP_private;
			}
			else
			{
				max_sock=sockfd_client;
			}

			int total_timer_events;
			FD_ZERO(&READ_SET);
	// Change while condition to reflect what is required for Project 1
	// ex: Routing table stabalization.
	while (1) {
		//if (total_timer_events >5)
			//exit(1);


		timersManager_->NextTimerTime(&tmv);
		if (tmv.tv_sec == 0 && tmv.tv_usec == 0) {
				//outfile_client<<"timer finished .... calling the function"<<endl;
		        // The timer at the head on the queue has expired
		        timersManager_->ExecuteNextTimer();

			continue;
		}
		if (tmv.tv_sec == MAXVALUE && tmv.tv_usec == 0){
		        // There are no timers in the event queue
		        break;
		}


		/* The select call here will wait for tv seconds before expiring
		 * You need to  modifiy it to listen to multiple sockets and add code for
		 * packet processing. Refer to the select man pages or "Unix Network
		 * Programming" by R. Stevens Pg 156.
		 */




					FD_SET(UDP_private,&READ_SET);
							FD_SET(sockfd_client,&READ_SET);
					status = select(max_sock+1,&READ_SET,NULL,NULL,&tmv);

					if (status<0)
						{perror("select");}


						else if (status == 0){
							//outfile_client<<"select timed out ..... again calling the timers function"<<endl;
									// Timer expired, Hence process it
								        timersManager_->ExecuteNextTimer();
									// Execute all timers that have expired.
									timersManager_->NextTimerTime(&tmv);

									while(tmv.tv_sec == 0 && tmv.tv_usec == 0){
									       // Timer at the head of the queue has expired
									        timersManager_->ExecuteNextTimer();
										timersManager_->NextTimerTime(&tmv);


									}
								}

						else if (status > 0){
					// The socket has received data.
					// Perform packet processing.
							//for(int i=1;i<33;i++)
								//					{
													//	outfile_client<<"client"<<hex<<MY_TOKEN<<"#"<<i<<":"<<hex<<FT[i].NODE_TOKEN<<"->"<<dec<<FT[i].udp_port<<endl;
											//		}
												//outfile_client<<"PREDECESSOR: "<<PREDECESSOR<<endl;
												//outfile_client<<"DOUBLE_SUCC: "<<DOUBLE_SUCC<<"port: "<<DOUBLE_SUCC_PORT<<endl;



						//outfile_client<<"data on socket ---------------"<<endl;
					///////////////////////
					// got msg on UDP port
					///////////////////////


					//cout<<"CLIENT:"<<CLIENT_NAME<<"->"<<" got from port"<<endl;

						if(FD_ISSET(UDP_private,&READ_SET))
										{
											int num_read1;
											outfile_client<<endl;
											//ioctl(UDP_private,FIONREAD,&num_read1);
											//if(num_read1<



											MARSHALLING_UDP obj;
											obj.RECEIVE(UDP_private);
										}
						if(FD_ISSET(sockfd_client,&READ_SET))
										{
											int num_read;
											 ioctl(sockfd_client,FIONREAD,&num_read);
											 if(num_read<=0)
											 {
												 continue;
											 }
											 //recv_tcp();
											 int numbytes_client;
											char RECV[100],RECV1[100];

											if ((numbytes_client = recv(sockfd_client, RECV, sizeof RECV, 0)) == -1)
															{
																perror("recv_TCP_client");
																exit(1);
															}
															//outfile_client<<"received msg from manager:"<<RECV<<endl;


											inst.instruction=strtok(RECV,"-");
											inst.DATA=strtok(NULL,"\0");
											//outfile_client<<"received msg :"<<inst.instruction<<endl;
											//outfile_client<<"received data :"<<inst.DATA<<endl;

											uint32_t data_hash= nonce_name_hash((uint32_t)(htonl(atoi(NONCE))),inst.DATA);



											char DUMMY_store[]="store";
											char DUMMY_search[]="search";
											char DUMMY_end_client[]="end_client";
											char DUMMY_kill_client[]="kill_client";
											int YES;
											uint32_t numbers[]={0,1,2,3};
											uint32_t temp;
											//cout<<"data hash is "<<hex<<data_hash<<endl;
											if (strcmp((char *)inst.instruction,DUMMY_store)==0  )
												{

													if(STAGE.compare("7")==0)
													{
														for (int i=0;i<4;i++)
														{
															data_hash=  (numbers[i]<<30) | (0x3fffffff & data_hash );
															cout<< "DATA_HASH VALUE IS ------->"<<hex<<data_hash<<endl;
															//DATA_HASH=data_hash;   // setting the global value of DATA_HASH
															store_func(data_hash);

														}
													}
													else
													{
														store_func(data_hash);
													}


												}
											else if(strcmp((char *)inst.instruction,DUMMY_search)==0 )
											{
												cout<<"&&&&&&&&&&&&&&&&&&& in SEARCH"<<endl;
												uint32_t min1,min2,temp,temporary;
												min1=0xffffffff;
												uint32_t diff[4];
												map <uint32_t,uint32_t> mapping;

												global_search_counter=0;

												if(STAGE.compare("7")==0)
												{
													for (int i=0;i<4;i++)
													{
														temp=  (numbers[i]<<30) | (0x3fffffff & data_hash );
														//cout<< "DATA_HASH VALUE IS ------->"<<hex<<data_hash<<endl;
														//DATA_HASH=data_hash;   // setting the global value of DATA_HASH
														diff[i] = calculate((uint64_t)temp,(uint64_t)MY_TOKEN,0);
														mapping[diff[i]]= temp;
														cout << diff[i] <<"->"<<hex<<mapping[diff[i]]<<endl;

													}

													for (int j=0;j<4;j++)   // sorting the differences
													{
														for (int k=j+1;k<4;k++)
														{
																if (diff[k]< diff[j] )
																{
																	temporary= diff[j];
																	diff[j]=diff[k];
																	diff[k]=temporary;
																}
														}
													}

													for (int g=0;g<4;g++)
													{
														cout<<"diff is: "<<diff[g]<<endl;
													}
													cout<< "nearest 2 are : "<< hex<<mapping[diff[0]]<<", "<<hex<<mapping[diff[1]]<<endl;

													search_func(mapping[diff[0]]);
													search_func(mapping[diff[1]]);


												}
												else
												{
													search_func(data_hash);
												}
											}

											else if(strcmp((char *)inst.instruction,DUMMY_kill_client)==0 )
												{
													cout<<"CLIENT: "<<CLIENT_NAME<<"-> killing my self ---- got the kill signal from manager"<<endl;
													//outfile_client<<endl;
													exit(1);
												}


										}

					} //end data on socket

	}// end while 1
	return;
}