virtual void deliverMessage(const ObjectReference& destination,
                             const RoutableMessage&opaqueMessage,
                             const void *optionalSerializedMessageBody,
                             size_t optionalSerializedMessageBodySize) {
     if (optionalSerializedMessageBody) {
         mObject->processMessage(opaqueMessage.header(),MemoryReference(optionalSerializedMessageBody,optionalSerializedMessageBodySize));
     }else {
         std::string bodyMsg;
         if (opaqueMessage.body().SerializeToString(&bodyMsg)) {
             mObject->processMessage(opaqueMessage.header(),MemoryReference(bodyMsg.data(),bodyMsg.size()));
         }
     }
 }
예제 #2
0
void Broadcast::initiateHandshake(Broadcast::BroadcastStream*stream,const Network::Address&addy,const UUID &name) {
    Protocol::Broadcast message;
    message.set_broadcast_name(name);
    String str;
    if (message.SerializeToString(&str)) {
        (*stream)->send(MemoryReference(str),Network::ReliableOrdered);
        //FIXME
    }else {
        SILOG(broadcast,error,"Cannot send memory reference to UUID "<<name.toString());
    }
}
예제 #3
0
void SingleStreamProximityConnection::processMessage(const RoutableMessageHeader&hdr,
                                                     MemoryReference message_body) {
    ObjectStreamMap::iterator where=mObjectStreams.find(hdr.has_source_object()?hdr.source_object():ObjectReference::null());
    if (where==mObjectStreams.end()) {
        where=mObjectStreams.find(hdr.has_destination_object()?hdr.destination_object():ObjectReference::null());
    }
    if (where==mObjectStreams.end()) {
        SILOG(proximity,error,"Cannot locate object with OR "<<hdr.source_object()<<" in the proximity connection map: "<<hdr.has_source_object());
    } else {
        std::string data;
        RoutableMessageHeader rmh;
        rmh.SerializeToString(&data);
        where->second->send(MemoryReference(data),message_body,Network::ReliableOrdered);
    }
}
예제 #4
0
	void flush_buffer(OutputBuffer buffer, size_type record_count){
		if(!m_context){
			throw std::runtime_error(
				"This OutputWriter is not corresponding to any tasks");
		}
		if(record_count > 0){
			auto sb = OutputBufferImpl::get_impl(buffer).unbind_fragment();
			sb.record_count(record_count);
			m_logical_task->commit_fragment(
				*m_context,
				m_output_port,
				0,
				MemoryReference(sb.raw_reference()));
		}
	}
예제 #5
0
void TimeSyncServer::handleMessage(const OHDP::Endpoint& src, const OHDP::Endpoint& dst, MemoryReference payload) {
    SILOG(timesync, detailed, "Received time sync message from remote node " << src.node());

    Sirikata::Protocol::TimeSync sync_msg;
    bool parse_success = sync_msg.ParseFromArray(payload.data(), payload.size());
    if (!parse_success) {
        LOG_INVALID_MESSAGE_BUFFER(sync, error, ((char*)payload.data()), payload.size());
        return;
    }

    // Our only job is to take the existing message, fill in a timestamp, and
    // send it back.
    sync_msg.set_t(mContext->simTime());
    String resp = serializePBJMessage(sync_msg);
    mPort->send(src, MemoryReference(resp));
    SILOG(timesync, detailed, "Sent time sync message reply to remote node " << src.node());
}
예제 #6
0
 void timedOut(const boost::system::error_code &error) {
     std::auto_ptr<TimerHandler> scopedDestructor(this);
     if (error == boost::asio::error::operation_aborted) {
         return; // don't care if the timer was cancelled.
     }
     RoutableMessageHeader msg;
     if (mSentMessage->header().has_destination_object()) {
         msg.set_source_object(mSentMessage->header().destination_object());
     }
     if (mSentMessage->header().has_destination_space()) {
         msg.set_source_space(mSentMessage->header().destination_space());
     }
     msg.set_source_port(mSentMessage->header().destination_port());
     msg.set_return_status(RoutableMessageHeader::TIMEOUT_FAILURE);
     msg.set_reply_id(mSentMessage->getId());
     mSentMessage->mTimerHandle=NULL;
     mSentMessage->mResponseCallback(mSentMessage, msg, MemoryReference(NULL,0));
     //formerly called this, but that asked asio to unset an ignored callback mSentMessage->processMessage(msg, MemoryReference(NULL,0));
 }
예제 #7
0
void HostedObject::receiveMessage(const SpaceID& space, const Protocol::Object::ObjectMessage* msg) {
    if (stopped()) {
        HO_LOG(detailed,"Ignoring received message after system stop requested.");
        return;
    }

    // Convert to ODP runtime format
    ODP::Endpoint src_ep(space, ObjectReference(msg->source_object()), msg->source_port());
    ODP::Endpoint dst_ep(space, ObjectReference(msg->dest_object()), msg->dest_port());

    if (mDelegateODPService->deliver(src_ep, dst_ep, MemoryReference(msg->payload()))) {
        // if this was true, it got delivered
        delete msg;
    }
    else {
        SILOG(cppoh,detailed,"[HO] Undelivered message from " << src_ep << " to " << dst_ep);
        delete msg;
    }

}
예제 #8
0
Chunk*ASIOSocketWrapper::constructControlPacket(const MultiplexedSocketPtr &thus, TCPStream::TCPStreamControlCodes code,const Stream::StreamID&sid) {
    const unsigned int max_size=16;
    switch (thus->getStreamType()) {
    case TCPStream::BASE64_ZERODELIM: {
        uint8 dataStream[max_size+Stream::StreamID::MAX_HEX_SERIALIZED_LENGTH+1];
        Stream::StreamID controlStream;//control packet
        unsigned int streamidsize=0;
        unsigned int size=streamidsize=controlStream.serializeToHex(&dataStream[0],max_size);
        assert(size<max_size);
        dataStream[size++]=code;
        unsigned int cur=size;
        size=max_size-cur;
        size=sid.serialize(&dataStream[cur],size);
        assert(size+cur<=max_size);
        MemoryReference serializedStreamId(dataStream,streamidsize);
        return toBase64ZeroDelim(MemoryReference(dataStream+streamidsize,size+cur-streamidsize),MemoryReference(NULL,0),MemoryReference(NULL,0),&serializedStreamId);
    }
    break;
    case TCPStream::RFC_6455: {
        uint8 dataStream[max_size + Stream::StreamID::MAX_SERIALIZED_LENGTH + 2];
        unsigned int packetHeaderLength = 2;
        unsigned int size = max_size;
        unsigned int cur = packetHeaderLength;
        Stream::StreamID controlStream;

        unsigned int streamidsize = controlStream.serialize(&dataStream[cur], max_size);
        assert(streamidsize < max_size);
        cur += streamidsize;
        dataStream[cur++] = code;
        size = max_size - cur;
        size = sid.serialize(&dataStream[cur], size);
        assert(size + cur <= max_size);
        MemoryReference serializedStreamId(&dataStream[packetHeaderLength], streamidsize);

        dataStream[0] = 0x80 | 0x02 ; // Flags = FIN/Unfragmented, Opcode = 2: binary data
        dataStream[1] = size + cur - packetHeaderLength; // Less than 125.

        return new Chunk(dataStream, dataStream + size + cur);
    }
    break;
    case TCPStream::LENGTH_DELIM:
    default: {
        uint8 dataStream[max_size+VariableLength::MAX_SERIALIZED_LENGTH+Stream::StreamID::MAX_SERIALIZED_LENGTH];
        unsigned int size=max_size;
        Stream::StreamID controlStream;//control packet
        size=controlStream.serialize(&dataStream[VariableLength::MAX_SERIALIZED_LENGTH],size);
        assert(size<max_size);
        dataStream[VariableLength::MAX_SERIALIZED_LENGTH+size++]=code;
        unsigned int cur=VariableLength::MAX_SERIALIZED_LENGTH+size;
        size=max_size-cur;
        size=sid.serialize(&dataStream[cur],size);
        assert(size+cur<=max_size);
        VariableLength streamSize=VariableLength(size+cur-VariableLength::MAX_SERIALIZED_LENGTH);
        unsigned int actualHeaderLength=streamSize.serialize(dataStream,VariableLength::MAX_SERIALIZED_LENGTH);
        if (actualHeaderLength!=VariableLength::MAX_SERIALIZED_LENGTH) {
            unsigned int retval=streamSize.serialize(dataStream+VariableLength::MAX_SERIALIZED_LENGTH-actualHeaderLength,VariableLength::MAX_SERIALIZED_LENGTH);
            assert(retval==actualHeaderLength);
        }
        return new Chunk(dataStream+VariableLength::MAX_SERIALIZED_LENGTH-actualHeaderLength,dataStream+size+cur);
    }
    break;
    }
}