00001 /* 00002 * Copyright (C) 2006, Jose Renato Santos. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 */ 00017 00018 // RioNeti.pkt 00019 #ifndef __RIONETI_PKT_ 00020 #define __RIONETI_PKT_ 00021 00022 /* -- RioNeti.pkt -- RioNeti wire packet prefix formats 00023 00024 This describes the "wire" format of the packet prefixes used 00025 by RioNeti. It assumes no padding in the structure and that 00026 the types sizes are "correct". 00027 00028 All packet prefixes start with the single byte packet type field. 00029 00030 All fields are ordered to be aligned on natural boundries. 00031 Explicit pad fields are added if needed (there should not 00032 be any implicit padding). 00033 00034 Multibyte binary fields are usually in network byte order 00035 except for fields which are only local to one system 00036 (like the requestid field which is opaque everywhere 00037 except on the system which picks it). 00038 00039 -- */ 00040 00041 /* -- fragment prefix format 00042 00043 A block to be sent is broken up into one or more fragments to 00044 enable them to fit in UDP packets. Each fragment of data is 00045 preceeded with this. 00046 00047 Each fragment is maximum length, except possibly the last (which 00048 has ??? set, fragment number of -1?). 00049 00050 There isn't any auth field in each fragment. Possibly there 00051 could be one over the whole block (RTT requests could 00052 skip generating/checking this?). 00053 00054 -- */ 00055 00056 00057 class RioPkt { 00058 00059 friend class RioNeti; 00060 00061 // prefix format (all formats) 00062 // (have different use of x1 x2 fields) 00063 00064 // type fields are a subset of the RioNeti::call_type enum 00065 00066 // rst format (reqid is from inbound "invalid" packet being rst which 00067 // is not the normal case. This requires an ip/port/reqid search 00068 // of the whole hash table to find the source which send the packet 00069 // which caused the rst). x2 carries the rst error code/result code. 00070 00071 // ack format (x1, x2 0). 00072 00073 // SendResult format is just pktp followed by u32 of the result code. 00074 00075 struct pktp 00076 { 00077 u8 type; 00078 u8 x1; 00079 u16 x2; 00080 u32 reqid; 00081 NetAuth auth; 00082 }; 00083 00084 // Nova estrutura para o ACK a mensagem que envia o mapeamento. Possui o IP e 00085 // a porta para quem o ACK foi enviado. Usada pela implementacao para dar 00086 // suporte aos clientes atras de NAT. 00087 00088 struct pktpmap 00089 { 00090 u8 type; 00091 u32 IP; 00092 u16 port; 00093 u32 reqid; 00094 NetAuth auth; 00095 }; 00096 00097 // fragment prefix 00098 struct pktfx 00099 { 00100 u8 type; 00101 u8 x1; 00102 u16 fragnum; 00103 u32 reqid; 00104 }; 00105 00106 // fragment 0 prefix (includes normal fragment prefix too) 00107 struct pktf0 00108 { 00109 struct pktfx pfx; 00110 // following only in fragment 0 00111 NetAuth auth; 00112 u32 ackreqid; 00113 u16 fragmax; 00114 u16 maxpktl; 00115 }; 00116 00117 // fragment ack format 00118 struct pktfa 00119 { 00120 u8 type; 00121 u8 x1; 00122 u16 fragackseq; // ack seq # 0 -> n 00123 u32 reqid; 00124 NetAuth auth; 00125 u16 fragnum; // # unique frags received 00126 u16 fraghigh; // highest frag # received 00127 // list of missing fragments in hole here (each u16) 00128 }; 00129 00130 }; // end of class RioPkt 00131 #endif /* __RIONETI_PKT_ */