Esempio n. 1
0
	//Saves a key to the USB path
	void Controller::saveUSBKey(os::smart_ptr<USBNode> node)
	{
		if(!node)return;

		//WATERMARK
		wrcerr<<"NOT FINISHED!!!!"<<endl;
		saveKey(node->getPath());
	}
Esempio n. 2
0
	//Receive from module
	void Connection::receive(os::smart_ptr<crypto::message> msg, os::smart_ptr<MessageType> type)
	{
		if(!type || !msg)
			return;

		//IP address case
		if(type->getID() == ipAddressMess.getID())
		{
			std::string str = msg->popString();
			while(str!="")
			{
				manager->getLocalIP()->insert(IPAddress(str));
				str = msg->popString();
			}
			return;
		}

		//String case
		if(type->isString())
		{
			std::string str = msg->popString();
			while(str!="")
			{
				tnetout<<"Message from "<<getName()<<": "<<str<<std::endl;
				str = msg->popString();
			}
			return;
		}

		//Attempt to process messages
		manager->getMaster()->receiveMessage(msg,type,this);
	}
Esempio n. 3
0
	//Main menu constructor
	networkMapForm::networkMapForm(gl::form* prev,os::smart_ptr<login::loginMetaData> metaData):
		fileDropDownForm(prev),controller(metaData->currentUser()),sideMenu(this,&controller)
	{
		_metaData=metaData;
		metaData->removeSender(os::cast<os::savable,crypto::user>(metaData->currentUser()));

		setTitle("Main Menu");
		setResizePolicy(gl::resize_lock);
		setTargHeight(600);
		setTargWidth(800);
		setWidth(600);
		setHeight(800);

		//Top bar binding
		os::smart_ptr<gl::barGroup> securityMenu(new gl::barGroup("Security"),os::shared_type);
		barTop.addChild(securityMenu);
		os::smart_ptr<gl::barGroup> connectionMenu(new gl::barGroup("Connection"),os::shared_type);
		barTop.addChild(connectionMenu);
		
		//Managing key
		btnSecuritySettings = os::smart_ptr<gl::barGroup>(new gl::barGroup("Settings"),os::shared_type);
        btnSecuritySettings->pushClickedListener(this);
		securityMenu->addChild(btnSecuritySettings);

		btnKeyBank = os::smart_ptr<gl::barGroup>(new gl::barGroup("Key Bank"),os::shared_type);
        btnKeyBank->pushClickedListener(this);
		securityMenu->addChild(btnKeyBank);

		//IP button form
		btnIPForm = os::smart_ptr<gl::barGroup>(new gl::barGroup("IP Form"),os::shared_type);
        btnIPForm->pushClickedListener(this);
		connectionMenu->addChild(btnIPForm);

        

		//Keyboard listeners
		addMouseListener(&sideMenu);
		addKeyboardListener(&sideMenu);
	}
Esempio n. 4
0
	//Constructor
	ConnectionModule::ConnectionModule(os::smart_ptr<Connection> m, os::smart_ptr<NetworkFramework> frm)
	{
		lock.lock();

		manager = frm->getManager();
		framework=frm;
		master = m;
		need_change_flag=false;
        if(master)master->bind(this);

		os::smart_ptr<crypto::user> usr=manager->getMaster()->getUser();
		if(usr->getDefaultPublicKey() && string(manager->getID())!= "NULL")
		{
			_gateway = smart_ptr<gateway>(new gateway(usr,manager->getGroupID()),shared_type);
		}
		else
		{
			tneterr<<"User data invalid, cannot build a gateway!"<<std::endl;
			abort();
		}
		resetChange();

		lock.unlock();
	}
Esempio n. 5
0
	//Process a received interior message
	void ConnectionModule::process_message(os::smart_ptr<crypto::message> msg,uint8_t datHead)
    {
		kill_test();

		//Check for a bad message, not polling case
		if(!msg)
			return;
		if(!manager->isPolling())
			return;
		
		lock.lock();
		message_lock.acquire();

		//Process message
        bool _isBase=false;
        bool _serverOn=false;
        if(datHead&1) _serverOn = true;
        if(datHead&2) _isBase = true;

		uint8_t curState=_gateway->currentState();

		//Received a legal message
		if(!master)
		{
			os::smart_ptr<crypto::gatewaySettings> tSet;
			if(msg->data()[0]==crypto::message::PING) tSet=os::smart_ptr<crypto::gatewaySettings>(new crypto::gatewaySettings(*msg),os::shared_type);
			else tSet=_gateway->getBrotherSettings();

			if(tSet)
			{
				//Bad name screening
				if(tSet->nodeName() == "NULL" || tSet->nodeName()==manager->getMaster()->getName())
				{
					message_lock.release();
					lock.unlock();
					return;
				}
				
				master = manager->find(tSet->groupID(),tSet->nodeName());
				if(master) master->bind(this);
			}
		}
		else if(msg->data()[0]==crypto::message::PING)
		{
			os::smart_ptr<crypto::gatewaySettings> tSet=os::smart_ptr<crypto::gatewaySettings>(new crypto::gatewaySettings(*msg),os::shared_type);
			//Bad name screening
			if(tSet->nodeName() == "NULL" || tSet->nodeName()==manager->getMaster()->getName())
			{
				message_lock.release();
				lock.unlock();
				return;
			}

			//Compare with master name
			os::smart_ptr<crypto::nodeGroup> ng=manager->getMaster()->getUser()->getKeyBank()->find(tSet->groupID(),tSet->nodeName());
			if(ng!=master->getNode())
			{
				master->remove(this);
				master = manager->find(tSet->groupID(),tSet->nodeName());
				if(master) master->bind(this);
			}
		}
		
		if(msg->data()[0]!=crypto::message::PING || (curState==crypto::gateway::UNKNOWN_STATE || curState==crypto::gateway::UNKNOWN_BROTHER
				|| curState==crypto::gateway::SETTINGS_EXCHANGED || curState==crypto::gateway::CONFIRM_ERROR_STATE))
			msg=_gateway->processMessage(msg);

		auto errMsg=_gateway->popError();
		while(errMsg)
		{
			tneterr<<errMsg->errorTitle()<<std::endl;
			errMsg=_gateway->popError();
		}

		//We don't have a master
		if(!master)
		{
			if(_gateway->secure())
			{
				os::smart_ptr<crypto::nodeGroup> ngr=_gateway->brotherNode();
				if(ngr) master=manager->insert(ngr,_isBase);
				master->bind(this);
			}
		}
		message_lock.release();
		lock.unlock();

        //Normal Message processing
		if(msg && !msg->encrypted())
        {
            os::smart_ptr<MessageType> found_type = getRegistry()->search(msg->data()[0]);
            
            //Unknown type, log
            if(found_type == NULL)
            {
                tneterr<<"No registered type!!!"<<endl;
				tneterr<<"Received marker "<<(int)msg->data()[0]<<endl;
            }
			else if(!found_type->gatewayMessage()) master->receive(msg,found_type);
        }
	}
Esempio n. 6
0
	//Receive a message
	//Triggered anytime a message is received
	void Controller::receiveMessage(os::smart_ptr<crypto::message> msg, os::smart_ptr<tnet::MessageType> type, os::smart_ptr<tnet::Connection> con)
	{
		if(!msg || !type || !con)
			return;

		if(type->getID()!=motorControlMessageType.getID() && type->getID()!=connectionListMessage.getID())
			return;

		//Pull from data
		os::smart_ptr<siblingData> tempDat(new siblingData(con),os::shared_type);
		auto fnd=connectionData.search(tempDat);
		if(!fnd) connectionData.insert(tempDat);
		else tempDat=&fnd;
		
		//Connection list case
		if(type->getID()==connectionListMessage.getID())
		{
			std::string strGroup,strName;
			strName=msg->popString();
			strGroup=msg->popString();
			while(strName!="" && strGroup!="")
			{
				auto temp=network()->find(strGroup,strName);
				if(temp)
					tempDat->eligibleConnections.insert(temp);
				strName=msg->popString();
				strGroup=msg->popString();
			}
			return;
		}
		tempDat->remoteType=msg->data()[1];

		//Joystick case
		if(tempDat->remoteType==RemoteController::JOYSTICK)
		{
			tempDat->xVal=(float)msg->data()[2]/256.0f;
			tempDat->yVal=(float)msg->data()[3]/256.0f;

			//Default settings
			tempDat->rightWheel=0;
			tempDat->leftWheel=0;

			tempDat->strMaster[0]="";
			tempDat->strMaster[1]="";

			tempDat->strConnection[0]="";
			tempDat->strConnection[1]="";
		}
		//Bot case
		else if(tempDat->remoteType==RemoteController::BOT)
		{
			tempDat->rightWheel=(float)msg->data()[2]/128.0f-1.0f;
			tempDat->leftWheel=(float)msg->data()[3]/128.0f-1.0f;

			char* strm;
			int arrSize;
			if(crypto::size::GROUP_SIZE>crypto::size::NAME_SIZE) arrSize=crypto::size::GROUP_SIZE;
			else arrSize=crypto::size::NAME_SIZE;
			strm=new char[arrSize+1];

			//Master name
			memset(strm,0,arrSize+1);
			memcpy(strm,msg->data()+4,crypto::size::GROUP_SIZE);
			tempDat->strMaster[0]=std::string(strm);
			memset(strm,0,arrSize+1);
			memcpy(strm,msg->data()+4+crypto::size::GROUP_SIZE,crypto::size::NAME_SIZE);
			tempDat->strMaster[1]=std::string(strm);

			//Connection name
			memset(strm,0,arrSize+1);
			memcpy(strm,msg->data()+4+crypto::size::GROUP_SIZE+crypto::size::NAME_SIZE,crypto::size::GROUP_SIZE);
			tempDat->strConnection[0]=std::string(strm);
			memset(strm,0,arrSize+1);
			memcpy(strm,msg->data()+4+2*crypto::size::GROUP_SIZE+crypto::size::NAME_SIZE,crypto::size::NAME_SIZE);
			tempDat->strConnection[1]=std::string(strm);

			delete [] strm;

			//Default settings
			tempDat->xVal=.5;
			tempDat->yVal=.5;
		}
		else tempDat->resetData();
	}