From: <sv...@ww...> - 2004-07-26 05:16:23
|
Author: mkrose Date: 2004-07-25 22:16:17 -0700 (Sun, 25 Jul 2004) New Revision: 1187 Modified: trunk/CSP/SimNet/MessageQueue.h trunk/CSP/SimNet/NetBase.h trunk/CSP/SimNet/NetworkMessage.h trunk/CSP/SimNet/PacketSource.h Log: Add routing type and routing data to PacketHeader and NetworkMessage. The basic idea is that these fields are used by the receiver to help dispatch the message to an object or class that knows how to interpret it. Putting these fields in the header makes sense, since they will be used universally, and it allows the dispatch layer to be ignorant of the message internals. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1187 Modified: trunk/CSP/SimNet/MessageQueue.h =================================================================== --- trunk/CSP/SimNet/MessageQueue.h 2004-07-26 05:11:53 UTC (rev 1186) +++ trunk/CSP/SimNet/MessageQueue.h 2004-07-26 05:16:17 UTC (rev 1187) @@ -69,6 +69,8 @@ PeerId destination = message->getDestination(); header->destination = destination; header->message_id = message->getCustomId(); + header->routing_type = message->getRoutingType(); + header->routing_data = message->getRoutingData(); m_Writer.bind(payload, payload_length); // XXX need to catch overflows message->serialize(m_TagWriter); Modified: trunk/CSP/SimNet/NetBase.h =================================================================== --- trunk/CSP/SimNet/NetBase.h 2004-07-26 05:11:53 UTC (rev 1186) +++ trunk/CSP/SimNet/NetBase.h 2004-07-26 05:16:17 UTC (rev 1187) @@ -40,9 +40,9 @@ */ typedef simdata::uint16 MessageId; -/** A type representing network bandwidth, in bytes per second. +/** A unique object id. (24-bits; 16 million ids) */ -typedef simdata::uint32 Bandwidth; +typedef simdata::uint32 ObjectId; /** An id number assigned to reliable messages and used to confirm * receipt of such messages. Ids are generated sequentially, per @@ -59,17 +59,19 @@ * reliable udp. */ struct PacketHeader { - simdata::uint16 reliable:1; // if true, header is actually a PacketReceiptHeader - simdata::uint16 reserved:2; // reserved for future use - simdata::uint16 priority:2; // 0 = non-realtime, 1=realtime, lopri, 2=realtime, hipri, 3=reliable - simdata::uint16 statmode:1; // 0 = desired send rate, 1 = fractional allocation - simdata::uint16 connstat:10; // if statmode == 0, the desired send rate as a fraction of the - // nominal receiver bandwidth: C * BW / 100 - // if statmode == 1, the fraction of the sender's inbound bandwidth - // allocated to the receiving peer (0->BW) - simdata::uint16 source; // id of the sender - simdata::uint16 destination; // id of the intended receiver - simdata::uint16 message_id; // id of the message + simdata::uint16 reliable:1; // if true, header is actually a PacketReceiptHeader + simdata::uint16 reserved:2; // reserved for future use + simdata::uint16 priority:2; // 0 = non-realtime, 1=realtime, lopri, 2=realtime, hipri, 3=reliable + simdata::uint16 statmode:1; // 0 = desired send rate, 1 = fractional allocation + simdata::uint16 connstat:10; // if statmode == 0, the desired send rate as a fraction of the + // nominal receiver bandwidth: C * BW / 100 + // if statmode == 1, the fraction of the sender's inbound bandwidth + // allocated to the receiving peer (0->BW) + simdata::uint16 source; // id of the sender + simdata::uint16 destination; // id of the intended receiver + simdata::uint16 message_id; // id of the message + simdata::uint32 routing_type:8; // routing type (e.g. object update, server handshake, etc.) + simdata::uint32 routing_data:24; // routing data (e.g. ObjectId for object update routing) }; Modified: trunk/CSP/SimNet/NetworkMessage.h =================================================================== --- trunk/CSP/SimNet/NetworkMessage.h 2004-07-26 05:11:53 UTC (rev 1186) +++ trunk/CSP/SimNet/NetworkMessage.h 2004-07-26 05:16:17 UTC (rev 1187) @@ -43,6 +43,8 @@ */ class NetworkMessage: public simdata::TaggedRecord { PeerId m_destination; + simdata::uint8 m_routing_type; + simdata::uint32 m_routing_data; unsigned char m_priority; public: @@ -51,7 +53,7 @@ /** Default constructor. Initializes to a non-reliable, low-priority * message. */ - NetworkMessage(): m_destination(0), m_priority(0) { } + NetworkMessage(): m_destination(0), m_routing_type(0), m_routing_data(0), m_priority(0) { } /** Get the peer id of the destination host. */ @@ -63,6 +65,34 @@ */ void setDestination(PeerId destination) { m_destination = destination; } + /** Set the message routing data. Interpretation of this value + * depends on the message routing type. + */ + void setRoutingData(simdata::uint32 data) { + assert((data & 0xFF00000) == 0); + m_routing_data = data; + } + + /** Get the message routing data. Interpretation of this value + * depends on the message routing type. + */ + simdata::uint32 getRoutingData() const { return m_routing_data; } + + /** Set the message routing type. Routing types are used to determine + * how to handle incoming messages. For example, if the routing type + * corresponds to an object message, the routing data will contain the + * id of the object to receive the message. This allow the message to + * be dispatched to the appropriate object without requiring the + * routing layer to understand the details of particular message types. + */ + void setRoutingType(simdata::uint8 type) { + m_routing_type = type; + } + + /** Get the message routing type. See setRoutingType for details. + */ + simdata::uint8 getRoutingType() const { return m_routing_type; } + /** Set the message to be "reliable." Reliable messages require a confirmation * of receipt from the destination host. The message will be resent periodically * until confirmation in received (or the peer is dropped). Reliable messages @@ -78,10 +108,12 @@ /** Set the priority of this message. There are four priority levels, interpreted * roughly as follows: - * 0 : low priority, non-realtime - * 1 : low priority, realtime - * 2 : realtime - * 3 : high priority, reliable + * + * @li 0 : low priority, non-realtime + * @li 1 : low priority, realtime + * @li 2 : realtime + * @li 3 : high priority, reliable + * * Setting the priority to 3 automatically selects reliable transmission. */ void setPriority(unsigned int priority) { Modified: trunk/CSP/SimNet/PacketSource.h =================================================================== --- trunk/CSP/SimNet/PacketSource.h 2004-07-26 05:11:53 UTC (rev 1186) +++ trunk/CSP/SimNet/PacketSource.h 2004-07-26 05:16:17 UTC (rev 1187) @@ -55,8 +55,8 @@ /** Retrieve the next packet. * - * @param header a packet header; the implementation needs to set the destination, priority, and - * message_id fields. + * @param header a packet header; the implementation needs to set the destination, priority, + * message_id, routing_type, and routing_data fields. * @param payload a buffer to receive the raw message data (excluding the header). * @param payload_length when called, the amount of space allocated for payload (in bytes); * on return the implementation must return the actual number of bytes used. |