当前位置: 首页>>代码示例>>C++>>正文


C++ PacketReader::current方法代码示例

本文整理汇总了C++中PacketReader::current方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketReader::current方法的具体用法?C++ PacketReader::current怎么用?C++ PacketReader::current使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PacketReader的用法示例。


在下文中一共展示了PacketReader::current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: buildPacket

bool WSSession::buildPacket(PacketReader& packet) {
	if (packet.available()<2)
		return false;
	UInt8 type = packet.read8() & 0x0F;
	UInt8 lengthByte = packet.read8();

	UInt32 size=lengthByte&0x7f;
	if (size==127) {
		if (packet.available()<8)
			return false;
		size = (UInt32)packet.read64();
	} else if (size==126) {
		if (packet.available()<2)
			return false;
		size = packet.read16();
	}

	if(lengthByte&0x80)
		size += 4;

	if (packet.available()<size)
		return false;

	packet.shrink(size);

	if (lengthByte & 0x80) {
		shared_ptr<WSUnmasking> pWSUnmasking(new WSUnmasking(invoker, packet.current(),packet.available(), type));
		decode<WSUnmasking>(pWSUnmasking);
	} else {
		packet.reset(packet.position()-1);
		*(UInt8*)packet.current() = type;
	}
	return true;
}
开发者ID:jaejungkim,项目名称:MonaServer,代码行数:34,代码来源:WSSession.cpp

示例2: Decode

bool RTMFP::Decode(Exception& ex,RTMFPEngine& aesDecrypt,PacketReader& packet) {
	// Decrypt
	aesDecrypt.process(packet.current(),(UInt8*)packet.current(),packet.available());
	bool result = ReadCRC(packet);
	if (!result)
		ex.set(Exception::CRYPTO, "Bad RTMFP CRC sum computing");
	return result;
}
开发者ID:luc1el,项目名称:MonaServer,代码行数:8,代码来源:RTMFP.cpp

示例3: Decode

bool RTMFP::Decode(AESEngine& aesDecrypt,PacketReader& packet) {
	// Decrypt
	aesDecrypt.process(packet.current(),packet.current(),packet.available());

	// Check the first 2 CRC bytes 
	packet.reset(4);
	UInt16 sum = packet.read16();
	return (sum == CheckSum(packet));
}
开发者ID:agazso,项目名称:Cumulus,代码行数:9,代码来源:RTMFP.cpp

示例4: add

	void add(PacketReader& fragment) {
		string::size_type old = _pBuffer->size();
		_pBuffer->resize(old + fragment.available(),true);
		if(_pBuffer->size()>old)
			memcpy(_pBuffer->data()+old,fragment.current(),fragment.available());
		++(UInt16&)fragments;
	}
开发者ID:taililong,项目名称:MonaServer,代码行数:7,代码来源:RTMFPFlow.cpp

示例5: pushVideoPacket

void Listener::pushVideoPacket(UInt32 time,PacketReader& packet) {
	if(!receiveVideo) {
		_firstKeyFrame=false;
		return;
	}
	if(!_pVideoWriter) {
		ERROR("Listener %u must be initialized before to be used",id);
		return;
	}
	// key frame ?
	if(((*packet.current())&0xF0) == 0x10)
		_firstKeyFrame=true;

	if(!_firstKeyFrame) {
		DEBUG("Video frame dropped for listener %u to wait first key frame",id);
		++(UInt32&)_pVideoWriter->qos.droppedFrames;
		return;
	}

	if(_pVideoWriter->reseted) {
		_pVideoWriter->reseted=false;
		writeBounds();
	}

	_pVideoWriter->write(computeTime(time),packet,_unbuffered);
}
开发者ID:191919,项目名称:Cumulus,代码行数:26,代码来源:Listener.cpp

示例6: add

	void add(PacketReader& fragment) {
		string::size_type old = _buffer.size();
		_buffer.resize(old + (string::size_type)fragment.available());
		if(_buffer.size()>old)
			memcpy(&_buffer[old],fragment.current(),(size_t)fragment.available());
		++(UInt16&)fragments;
	}
开发者ID:wilkystorm,项目名称:Cumulus,代码行数:7,代码来源:Flow.cpp

示例7: packetHandler

void ServerConnection::packetHandler(PacketReader& packet) {

	UInt8 marker = packet.read8();
	if(marker!=0x0b) {
		ERROR("ServerConnection with an unknown %u marker, it should be 0x0b",marker);
		return;
	}

	packet.next(2);
	UInt8 id = packet.read8();
	switch(id) {
		case 0x71: {
			packet.next(2);
			string tag;
			packet.readString8(tag);
			map<string,P2PHandshakerAddress>::iterator it = _p2pHandshakers.find(tag);
			if(it==_p2pHandshakers.end()) {
				ERROR("Unknown ServerConnection tag %s on P2P handshake",tag.c_str());
				break;
			}

			(SocketAddress&)_handshake.peer.address = it->second;
			packet.reset(0);
			PacketWriter writer(packet.current(),packet.available()+16); // +16 for futur 0xFFFF padding
			writer.clear(packet.available());
			_handshake.send(writer);
			_p2pHandshakers.erase(it);

			break;
		}
		case 0x40: {
			if(!_connected) {
				// Edge hello response
				_connected=true;
				return;
			}
			// Edge keepalive
			PacketWriter& packet(writer());
			packet.write8(0x41);
			packet.write16(0);
			flush();
			INFO("Keepalive RTMFP server");
			break;
		}
		case 0x45: {
			// Server is death!
			(bool&)died=true;
			break;
		}
		default:
			ERROR("Unkown ServerConnection packet id %u",id);
	}


}
开发者ID:Windslash,项目名称:Cumulus,代码行数:55,代码来源:ServerConnection.cpp

示例8: pushDataPacket

void Listener::pushDataPacket(const string& name,PacketReader& packet) {
	// TODO create _dataWriter ??
	if(_unbuffered) {
		UInt16 offset = name.size()+9;
		if(packet.position()>=offset) {
			packet.reset(packet.position()-offset);
			_writer.writeUnbufferedMessage(packet.current(),packet.available());
			return;
		}
		WARN("Written unbuffered impossible, it requires %u head bytes available on PacketReader given",offset);
	}
	StreamCopier::copyStream(packet.stream(),_writer.writeAMFPacket(name).writer.stream());
}
开发者ID:cvarrick,项目名称:Cumulus,代码行数:13,代码来源:Listener.cpp

示例9: writeMedia

bool WSWriter::writeMedia(MediaType type,UInt32 time,PacketReader& packet,Parameters& properties) {
	if(state()==CLOSED)
		return true;
	switch(type) {
		case START:
			writeInvocation("__publishing").writeString(string((const char*)packet.current(),packet.available()));
			break;
		case STOP:
			writeInvocation("__unpublishing").writeString(string((const char*)packet.current(),packet.available()));
			break;
		case DATA: {
			JSONWriter& writer = newDataWriter();
			writer.packet.write8('[');
			writer.packet.writeRaw(packet.current(),packet.available());
			writer.packet.write8(']');
			break;
		}
		case INIT:
			break;
		default:
			return Writer::writeMedia(type,time,packet,properties);
	}
	return true;
}
开发者ID:taililong,项目名称:MonaServer,代码行数:24,代码来源:WSWriter.cpp

示例10: write

	void write(UInt32 time,PacketReader& data,bool unbuffered) {
	//	if(_type==0x08)
	//		time=0;
	/*	if(_type==0x09)
			TRACE("Video timestamp : %u",_time)
		else
			TRACE("Audio timestamp : %u",_time);*/
		if(unbuffered) {
			if(data.position()>=5) {
				data.reset(data.position()-5);
				PacketWriter writer(data.current(),5);
				writer.write8(_type);
				writer.write32(time);
				writeUnbufferedMessage(data.current(),data.available(),data.current(),5);
				return;
			}
			WARN("Written unbuffered impossible, it requires 5 head bytes available on PacketReader given");
		}
		BinaryWriter& out = writeRawMessage(true);
		out.write8(_type);
		out.write32(time);
		StreamCopier::copyStream(data.stream(),out.stream());

	}
开发者ID:cvarrick,项目名称:Cumulus,代码行数:24,代码来源:Listener.cpp

示例11: packetHandler

void WSSession::packetHandler(PacketReader& packet) {
	UInt8 type = 0;
	Exception ex;
	if(peer.connected) {
		type = packet.read8();	
		
		switch(type) {
			case WS::TYPE_BINARY: {
				RawReader reader(packet);
				peer.onMessage(ex, "onMessage",reader,WS::TYPE_BINARY);
				break;
			}
			case WS::TYPE_TEXT: {
				if(!JSONReader::IsValid(packet)) {
					RawReader reader(packet);
					peer.onMessage(ex, "onMessage",reader);
					break;
				}
				JSONReader reader(packet);
				if(reader.followingType()!=JSONReader::STRING) {
					peer.onMessage(ex, "onMessage",reader);
					break;
				}
				string name;
				reader.readString(name);
				if(name=="__publish") {
					if(reader.followingType()!=JSONReader::STRING) {
						ex.set(Exception::PROTOCOL, "__publish method takes a stream name in first parameter",WS::CODE_MALFORMED_PAYLOAD);
						break;
					}
					reader.readString(name);
					if(_pPublication)
						invoker.unpublish(peer,_pPublication->name());
					_pPublication = invoker.publish(ex, peer,name);
				} else if(name=="__play") {
					if(reader.followingType()!=JSONReader::STRING) {
						ex.set(Exception::PROTOCOL, "__play method takes a stream name in first parameter",WS::CODE_MALFORMED_PAYLOAD);
						break;
					}
					reader.readString(name);
					
					closeSusbcription();
				} else if(name=="__closePublish") {
					closePublication();
				} else if(name=="__closePlay") {
					closeSusbcription();
				} else if (name == "__close") {
					closePublication();
					closeSusbcription();
					
				} else if(_pPublication) {
					reader.reset();
					_pPublication->pushData(reader);
				} else
					peer.onMessage(ex, name,reader);
				break;
			}
			case WS::TYPE_CLOSE:
				_writer.close(packet.available() ? packet.read16() : 0);
				break;
			case WS::TYPE_PING:
				_writer.writePong(packet.current(),packet.available());
				break;
			case WS::TYPE_PONG:
				peer.setPing(_writer.ping = (UInt16)(_time.elapsed()/1000));
				break;
			default:
				ex.set(Exception::PROTOCOL, Format<UInt8>("Type %#x unknown", type), WS::CODE_MALFORMED_PAYLOAD);
				break;
		}
		
		if (ex) {
			ERROR(ex.error());
			_writer.close((ex.code()==Exception::APPLICATION || ex.code() == Exception::SOFTWARE) ? WS::CODE_PROTOCOL_ERROR : ex.code());	
		}
		
	}

	if(!peer.connected || type==WS::TYPE_CLOSE)
		kill();
	else
		_writer.flush();
}
开发者ID:jaejungkim,项目名称:MonaServer,代码行数:83,代码来源:WSSession.cpp

示例12: messageHandler

void Flow::messageHandler(UInt32 stage,PacketReader& message,UInt8 flags) {
	if(_completed)
		return;

	if(stage<=_stage) {
		DEBUG("Stage %u on flow %u has already been received",stage,id);
		return;
	}
	_stage = stage;

	PacketReader* pMessage(NULL);
	if(flags&MESSAGE_WITH_BEFOREPART){
		if(_sizeBuffer==0) {
			ERROR("A received message tells to have a 'afterpart' and nevertheless partbuffer is empty");
			return;
		}
		
		UInt8* pOldBuffer = _pBuffer;
		_pBuffer = new UInt8[_sizeBuffer + message.available()]();
		memcpy(_pBuffer,pOldBuffer,_sizeBuffer);
		memcpy(_pBuffer+_sizeBuffer,message.current(),message.available());
		_sizeBuffer += message.available();
		delete [] pOldBuffer;

		if(flags&MESSAGE_WITH_AFTERPART)
			return;

		pMessage = new PacketReader(_pBuffer,_sizeBuffer);
	} else if(flags&MESSAGE_WITH_AFTERPART) {
		if(_sizeBuffer>0) {
			ERROR("A received message tells to have not 'beforepart' and nevertheless partbuffer exists");
			delete [] _pBuffer;
			_sizeBuffer=0;
		}
		_sizeBuffer = message.available();
		_pBuffer = new UInt8[_sizeBuffer]();
		memcpy(_pBuffer,message.current(),_sizeBuffer);
		return;
	}
	if(!pMessage)
		pMessage = new PacketReader(message);

	UInt8 type = unpack(*pMessage);
	if(type!=EMPTY) {
		writer._callbackHandle = 0;
		string name;
		AMFReader amf(*pMessage);
		if(type==AMF_WITH_HANDLER || type==AMF) {
			amf.read(name);
			if(type==AMF_WITH_HANDLER) {
				writer._callbackHandle = amf.readNumber();
				amf.skipNull();
			}
		}

		// create code prefix
		writer._code.assign(_name);
		if(!name.empty()) {
			writer._code.append(".");
			writer._code.push_back(toupper(name[0]));
			if(name.size()>1)
				writer._code.append(&name[1]);
		}

		switch(type) {
			case AMF_WITH_HANDLER:
			case AMF:
				messageHandler(name,amf);
				break;
			case AUDIO:
				audioHandler(*pMessage);
				break;
			case VIDEO:
				videoHandler(*pMessage);
				break;
			default:
				rawHandler(type,*pMessage);
		}
	}

	delete pMessage;

	if(flags&MESSAGE_END)
		complete();

	if(_sizeBuffer>0) {
		delete [] _pBuffer;
		_sizeBuffer=0;
	}
}
开发者ID:jacobdam,项目名称:Cumulus,代码行数:90,代码来源:Flow.cpp

示例13: targetPacketHandler

void Middle::targetPacketHandler(PacketReader& packet) {

	if(_firstResponse)
		((Timestamp&)peer.lastReceptionTime).update(); // To emulate a long ping corresponding, otherwise client send multiple times each packet
	_firstResponse = false;

	UInt8 marker = packet.read8();
	
	_timeSent = packet.read16(); // time

	UInt16 timeEcho(0);
	if((marker|0xF0) == 0xFE)
		timeEcho = packet.read16(); // time echo

	PacketWriter& packetOut = writer();

	int pos = packetOut.position();

	UInt8 type = packet.available()>0 ? packet.read8() : 0xFF;

	UInt64 idFlow,stage;
	UInt8 nbPeerSent = 0;

	while(type!=0xFF) {
		int posType = packetOut.position();
		packetOut.write8(type);

		UInt16 size = packet.read16();
		PacketReader content(packet.current(),size);packetOut.write16(size);

		if(type==0x10 || type==0x11) {
			UInt8 flag = content.read8();packetOut.write8(flag);
			if(type==0x10) {
				idFlow = content.read7BitLongValue();packetOut.write7BitLongValue(idFlow);
				stage = content.read7BitLongValue();packetOut.write7BitLongValue(stage);
				packetOut.write7BitLongValue(content.read7BitLongValue());
			} else
				++stage;
			
			if(!(flag&MESSAGE_WITH_BEFOREPART)) {

				if(flag&MESSAGE_HEADER) {
					UInt8 len = content.read8(); packetOut.write8(len);
					while(len!=0) {
						packetOut.writeRaw(content.current(),len);
						content.next(len);
						len = content.read8(); packetOut.write8(len);
					}
				}

				UInt8 flagType = content.read8(); packetOut.write8(flagType);
				if(flagType==0x09) {
					UInt32 time = content.read32(); packetOut.write32(time);
					TRACE("Timestamp/Flag video : %u/%2x",time,*content.current());
				} else if(flagType==0x08) {
					UInt32 time = content.read32(); packetOut.write32(time);
					TRACE("Timestamp/Flag audio : %u/%2x",time,*content.current());
				} else if(flagType==0x04) {
					packetOut.write32(content.read32());
					UInt16 a = content.read16();packetOut.write16(a);
					UInt32 b = content.read32(); packetOut.write32(b);
					if(content.available()>0) {
						UInt32 c = content.read32(); packetOut.write32(c);
						if(a!=0x22) {
							DEBUG("Raw %llu : %.2x %u %u",idFlow,a,b,c)
						} else {
							TRACE("Bound %llu : %.2x %u %u",idFlow,a,b,c);
						}
					} else
						DEBUG("Raw %llu : %.2x %u",idFlow,a,b)
					
				/*	if(a==0x1F) {
						packetOut.reset(posType);
						content.next(content.available());
					}*/
				}
开发者ID:OpenRTMFP,项目名称:Cumulus,代码行数:76,代码来源:Middle.cpp

示例14: packetHandler

void Middle::packetHandler(PacketReader& packet) {
	if(!_pMiddleAesEncrypt)
		manage(); // to wait the target handshake response

	// Middle to target
	PacketWriter& request = requester();

	UInt8 marker = packet.read8();
	request << marker;

	request << packet.read16();

	if((marker|0xF0) == 0xFD)
		request.write16(packet.read16()); // time echo

	int pos = request.position();

	UInt8 type = packet.available()>0 ? packet.read8() : 0xFF;
	while(type!=0xFF) {
		UInt16 size = packet.read16();
		PacketReader content(packet.current(),size);

		PacketWriter out(request.begin()+request.position(),request.available()); // 3 for future type and size
		out.clear(3);

		if(type==0x10) {

			out.write8(content.read8());
			UInt64 idFlow = content.read7BitLongValue();out.write7BitLongValue(idFlow);
			UInt64 stage = content.read7BitLongValue();out.write7BitLongValue(stage);

			if(idFlow==0x02 && stage==0x01) {
				if(!_isPeer) {
				
					/// Replace NetConnection infos

					out.writeRaw(content.current(),14);content.next(14);

					// first string
					string tmp;
					content.readString16(tmp);out.writeString16(tmp);

					AMFWriter writer(out);
					writer.amf0Preference=true;
					AMFReader reader(content);
					writer.writeNumber(reader.readNumber()); // double
					
					AMFSimpleObject obj;
					reader.readSimpleObject(obj);
					
					/// Replace tcUrl
					if(obj.has("tcUrl"))
						obj.setString("tcUrl",_queryUrl);
					
					writer.writeSimpleObject(obj);

				} else {

					out.writeRaw(content.current(),3);content.next(3);
					UInt16 netGroupHeader = content.read16();out.write16(netGroupHeader);
					if(netGroupHeader==0x4752) {

						map<string,string>::const_iterator it = peer.properties.find("groupspec");
						if(it!=peer.properties.end()) {
							out.writeRaw(content.current(),71);content.next(71);
							UInt8 result1[AES_KEY_SIZE];
							UInt8 result2[AES_KEY_SIZE];
							HMAC(EVP_sha256(),&_sharedSecret[0],_sharedSecret.size(),&_targetNonce[0],_targetNonce.size(),result1,NULL);
							HMAC(EVP_sha256(),it->second.c_str(),it->second.size(),result1,AES_KEY_SIZE,result2,NULL);
							out.writeRaw(result2,AES_KEY_SIZE);content.next(AES_KEY_SIZE);
							out.writeRaw(content.current(),4);content.next(4);
							out.writeRaw(_target.peerId,ID_SIZE);content.next(ID_SIZE);
						} else
							WARN("No groupspec client property indicated to make working the 'man-in-the-middle' mode between peers in a NetGroup case");
						
					}
				}
			}

		}  else if(type == 0x4C) {
			 kill();
			 return;
		}  else if(type == 0x51) {
			//printf("%s\n",Util::FormatHex(content.current(),content.available()).c_str());
		}
		out.writeRaw(content.current(),content.available());

		packet.next(size);

		if(out.length()>=3) {
			request<<type;
			size = out.length()-3;
			request.write16(size);request.next(size);
		}


		type = packet.available()>0 ? packet.read8() : 0xFF;
	}

	if(request.length()>pos)
//.........这里部分代码省略.........
开发者ID:OpenRTMFP,项目名称:Cumulus,代码行数:101,代码来源:Middle.cpp

示例15: handshakeHandler

UInt8 Handshake::handshakeHandler(UInt8 id,PacketReader& request,PacketWriter& response) {

	switch(id){
		case 0x30: {
			
			request.read8(); // passer un caractere (boite dans boite)
			UInt8 epdLen = request.read8()-1;

			UInt8 type = request.read8();

			string epd;
			request.readRaw(epdLen,epd);

			string tag;
			request.readRaw(16,tag);
			response.writeString8(tag);
			
			if(type == 0x0f)
				return _gateway.p2pHandshake(tag,response,peer.address,(const UInt8*)epd.c_str());

			if(type == 0x0a){
				/// Handshake
				HelloAttempt& attempt = helloAttempt<HelloAttempt>(tag);

				// Fill peer infos
				UInt16 port;
				string host;
				Util::UnpackUrl(epd,host,port,(string&)peer.path,(map<string,string>&)peer.properties);
				set<string> addresses;
				peer.onHandshake(attempt.count+1,addresses);
				if(!addresses.empty()) {
					set<string>::iterator it;
					for(it=addresses.begin();it!=addresses.end();++it) {
						try {
							if((*it)=="again")
								((string&)*it).assign(format("%s:%hu",host,port));
							SocketAddress address(*it);
							response.writeAddress(address,it==addresses.begin());
						} catch(Exception& ex) {
							ERROR("Bad redirection address %s in hello attempt, %s",(*it)=="again" ? epd.c_str() : (*it).c_str(),ex.displayText().c_str());
						}
					}
					return 0x71;
				}

				// New Cookie
				createCookie(response,attempt,tag,epd);

				// instance id (certificat in the middle)
				response.writeRaw(_certificat,sizeof(_certificat));
				return 0x70;
			} else
				ERROR("Unkown handshake first way with '%02x' type",type);
			break;
		}
		case 0x38: {
			(UInt32&)farId = request.read32();

			if(request.read7BitLongValue()!=COOKIE_SIZE) {
				ERROR("Bad handshake cookie '%s': its size should be 64 bytes",Util::FormatHex(request.current(),COOKIE_SIZE).c_str());
				return 0;
			}
	
			map<const UInt8*,Cookie*,CompareCookies>::iterator itCookie = _cookies.find(request.current());
			if(itCookie==_cookies.end()) {
				WARN("Cookie %s unknown, maybe already connected (udpBuffer congested?)",Util::FormatHex(request.current(),COOKIE_SIZE).c_str());
				return 0;
			}

			Cookie& cookie(*itCookie->second);
			(SocketAddress&)cookie.peerAddress = peer.address;

			if(cookie.farId==0) {
				((UInt32&)cookie.farId) = farId;
				request.next(COOKIE_SIZE);

				size_t size = (size_t)request.read7BitLongValue();
				// peerId = SHA256(farPubKey)
				EVP_Digest(request.current(),size,(UInt8*)cookie.peerId,NULL,EVP_sha256(),NULL);

				cookie.initiatorKey().resize(request.read7BitValue()-2);
				request.next(2); // unknown
				request.readRaw(&cookie.initiatorKey()[0],cookie.initiatorKey().size());

				cookie.initiatorNonce().resize(request.read7BitValue());
				request.readRaw(&cookie.initiatorNonce()[0],cookie.initiatorNonce().size());

				cookie.computeKeys();
			} else if(cookie.id>0) {
				// Repeat cookie reponse!
				cookie.read(response);
				return 0x78;
			} // else Keys are computing (multi-thread)

			break;
		}
		default:
			ERROR("Unkown handshake packet id %u",id);
	}

//.........这里部分代码省略.........
开发者ID:null-null-cn,项目名称:Cumulus,代码行数:101,代码来源:Handshake.cpp


注:本文中的PacketReader::current方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。