OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #include "webrtc/base/buffer.h" | 30 #include "webrtc/base/buffer.h" |
31 #include "webrtc/base/bytebuffer.h" | 31 #include "webrtc/base/bytebuffer.h" |
32 #include "webrtc/base/logging.h" | 32 #include "webrtc/base/logging.h" |
33 | 33 |
34 namespace webrtc { | 34 namespace webrtc { |
35 | 35 |
36 // Format defined at | 36 // Format defined at |
37 // http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-01#section | 37 // http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-01#section |
38 | 38 |
39 static const uint8 DATA_CHANNEL_OPEN_MESSAGE_TYPE = 0x03; | 39 static const uint8_t DATA_CHANNEL_OPEN_MESSAGE_TYPE = 0x03; |
40 static const uint8 DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE = 0x02; | 40 static const uint8_t DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE = 0x02; |
41 | 41 |
42 enum DataChannelOpenMessageChannelType { | 42 enum DataChannelOpenMessageChannelType { |
43 DCOMCT_ORDERED_RELIABLE = 0x00, | 43 DCOMCT_ORDERED_RELIABLE = 0x00, |
44 DCOMCT_ORDERED_PARTIAL_RTXS = 0x01, | 44 DCOMCT_ORDERED_PARTIAL_RTXS = 0x01, |
45 DCOMCT_ORDERED_PARTIAL_TIME = 0x02, | 45 DCOMCT_ORDERED_PARTIAL_TIME = 0x02, |
46 DCOMCT_UNORDERED_RELIABLE = 0x80, | 46 DCOMCT_UNORDERED_RELIABLE = 0x80, |
47 DCOMCT_UNORDERED_PARTIAL_RTXS = 0x81, | 47 DCOMCT_UNORDERED_PARTIAL_RTXS = 0x81, |
48 DCOMCT_UNORDERED_PARTIAL_TIME = 0x82, | 48 DCOMCT_UNORDERED_PARTIAL_TIME = 0x82, |
49 }; | 49 }; |
50 | 50 |
51 bool ParseDataChannelOpenMessage(const rtc::Buffer& payload, | 51 bool ParseDataChannelOpenMessage(const rtc::Buffer& payload, |
52 std::string* label, | 52 std::string* label, |
53 DataChannelInit* config) { | 53 DataChannelInit* config) { |
54 // Format defined at | 54 // Format defined at |
55 // http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 | 55 // http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 |
56 | 56 |
57 rtc::ByteBuffer buffer(payload); | 57 rtc::ByteBuffer buffer(payload); |
58 uint8 message_type; | 58 uint8_t message_type; |
59 if (!buffer.ReadUInt8(&message_type)) { | 59 if (!buffer.ReadUInt8(&message_type)) { |
60 LOG(LS_WARNING) << "Could not read OPEN message type."; | 60 LOG(LS_WARNING) << "Could not read OPEN message type."; |
61 return false; | 61 return false; |
62 } | 62 } |
63 if (message_type != DATA_CHANNEL_OPEN_MESSAGE_TYPE) { | 63 if (message_type != DATA_CHANNEL_OPEN_MESSAGE_TYPE) { |
64 LOG(LS_WARNING) << "Data Channel OPEN message of unexpected type: " | 64 LOG(LS_WARNING) << "Data Channel OPEN message of unexpected type: " |
65 << message_type; | 65 << message_type; |
66 return false; | 66 return false; |
67 } | 67 } |
68 | 68 |
69 uint8 channel_type; | 69 uint8_t channel_type; |
70 if (!buffer.ReadUInt8(&channel_type)) { | 70 if (!buffer.ReadUInt8(&channel_type)) { |
71 LOG(LS_WARNING) << "Could not read OPEN message channel type."; | 71 LOG(LS_WARNING) << "Could not read OPEN message channel type."; |
72 return false; | 72 return false; |
73 } | 73 } |
74 | 74 |
75 uint16 priority; | 75 uint16_t priority; |
76 if (!buffer.ReadUInt16(&priority)) { | 76 if (!buffer.ReadUInt16(&priority)) { |
77 LOG(LS_WARNING) << "Could not read OPEN message reliabilility prioirty."; | 77 LOG(LS_WARNING) << "Could not read OPEN message reliabilility prioirty."; |
78 return false; | 78 return false; |
79 } | 79 } |
80 uint32 reliability_param; | 80 uint32_t reliability_param; |
81 if (!buffer.ReadUInt32(&reliability_param)) { | 81 if (!buffer.ReadUInt32(&reliability_param)) { |
82 LOG(LS_WARNING) << "Could not read OPEN message reliabilility param."; | 82 LOG(LS_WARNING) << "Could not read OPEN message reliabilility param."; |
83 return false; | 83 return false; |
84 } | 84 } |
85 uint16 label_length; | 85 uint16_t label_length; |
86 if (!buffer.ReadUInt16(&label_length)) { | 86 if (!buffer.ReadUInt16(&label_length)) { |
87 LOG(LS_WARNING) << "Could not read OPEN message label length."; | 87 LOG(LS_WARNING) << "Could not read OPEN message label length."; |
88 return false; | 88 return false; |
89 } | 89 } |
90 uint16 protocol_length; | 90 uint16_t protocol_length; |
91 if (!buffer.ReadUInt16(&protocol_length)) { | 91 if (!buffer.ReadUInt16(&protocol_length)) { |
92 LOG(LS_WARNING) << "Could not read OPEN message protocol length."; | 92 LOG(LS_WARNING) << "Could not read OPEN message protocol length."; |
93 return false; | 93 return false; |
94 } | 94 } |
95 if (!buffer.ReadString(label, (size_t) label_length)) { | 95 if (!buffer.ReadString(label, (size_t) label_length)) { |
96 LOG(LS_WARNING) << "Could not read OPEN message label"; | 96 LOG(LS_WARNING) << "Could not read OPEN message label"; |
97 return false; | 97 return false; |
98 } | 98 } |
99 if (!buffer.ReadString(&config->protocol, protocol_length)) { | 99 if (!buffer.ReadString(&config->protocol, protocol_length)) { |
100 LOG(LS_WARNING) << "Could not read OPEN message protocol."; | 100 LOG(LS_WARNING) << "Could not read OPEN message protocol."; |
(...skipping 18 matching lines...) Expand all Loading... |
119 case DCOMCT_ORDERED_PARTIAL_TIME: | 119 case DCOMCT_ORDERED_PARTIAL_TIME: |
120 case DCOMCT_UNORDERED_PARTIAL_TIME: | 120 case DCOMCT_UNORDERED_PARTIAL_TIME: |
121 config->maxRetransmitTime = reliability_param; | 121 config->maxRetransmitTime = reliability_param; |
122 break; | 122 break; |
123 } | 123 } |
124 return true; | 124 return true; |
125 } | 125 } |
126 | 126 |
127 bool ParseDataChannelOpenAckMessage(const rtc::Buffer& payload) { | 127 bool ParseDataChannelOpenAckMessage(const rtc::Buffer& payload) { |
128 rtc::ByteBuffer buffer(payload); | 128 rtc::ByteBuffer buffer(payload); |
129 uint8 message_type; | 129 uint8_t message_type; |
130 if (!buffer.ReadUInt8(&message_type)) { | 130 if (!buffer.ReadUInt8(&message_type)) { |
131 LOG(LS_WARNING) << "Could not read OPEN_ACK message type."; | 131 LOG(LS_WARNING) << "Could not read OPEN_ACK message type."; |
132 return false; | 132 return false; |
133 } | 133 } |
134 if (message_type != DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE) { | 134 if (message_type != DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE) { |
135 LOG(LS_WARNING) << "Data Channel OPEN_ACK message of unexpected type: " | 135 LOG(LS_WARNING) << "Data Channel OPEN_ACK message of unexpected type: " |
136 << message_type; | 136 << message_type; |
137 return false; | 137 return false; |
138 } | 138 } |
139 return true; | 139 return true; |
140 } | 140 } |
141 | 141 |
142 bool WriteDataChannelOpenMessage(const std::string& label, | 142 bool WriteDataChannelOpenMessage(const std::string& label, |
143 const DataChannelInit& config, | 143 const DataChannelInit& config, |
144 rtc::Buffer* payload) { | 144 rtc::Buffer* payload) { |
145 // Format defined at | 145 // Format defined at |
146 // http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-00#section-6.1 | 146 // http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-00#section-6.1 |
147 uint8 channel_type = 0; | 147 uint8_t channel_type = 0; |
148 uint32 reliability_param = 0; | 148 uint32_t reliability_param = 0; |
149 uint16 priority = 0; | 149 uint16_t priority = 0; |
150 if (config.ordered) { | 150 if (config.ordered) { |
151 if (config.maxRetransmits > -1) { | 151 if (config.maxRetransmits > -1) { |
152 channel_type = DCOMCT_ORDERED_PARTIAL_RTXS; | 152 channel_type = DCOMCT_ORDERED_PARTIAL_RTXS; |
153 reliability_param = config.maxRetransmits; | 153 reliability_param = config.maxRetransmits; |
154 } else if (config.maxRetransmitTime > -1) { | 154 } else if (config.maxRetransmitTime > -1) { |
155 channel_type = DCOMCT_ORDERED_PARTIAL_TIME; | 155 channel_type = DCOMCT_ORDERED_PARTIAL_TIME; |
156 reliability_param = config.maxRetransmitTime; | 156 reliability_param = config.maxRetransmitTime; |
157 } else { | 157 } else { |
158 channel_type = DCOMCT_ORDERED_RELIABLE; | 158 channel_type = DCOMCT_ORDERED_RELIABLE; |
159 } | 159 } |
160 } else { | 160 } else { |
161 if (config.maxRetransmits > -1) { | 161 if (config.maxRetransmits > -1) { |
162 channel_type = DCOMCT_UNORDERED_PARTIAL_RTXS; | 162 channel_type = DCOMCT_UNORDERED_PARTIAL_RTXS; |
163 reliability_param = config.maxRetransmits; | 163 reliability_param = config.maxRetransmits; |
164 } else if (config.maxRetransmitTime > -1) { | 164 } else if (config.maxRetransmitTime > -1) { |
165 channel_type = DCOMCT_UNORDERED_PARTIAL_TIME; | 165 channel_type = DCOMCT_UNORDERED_PARTIAL_TIME; |
166 reliability_param = config.maxRetransmitTime; | 166 reliability_param = config.maxRetransmitTime; |
167 } else { | 167 } else { |
168 channel_type = DCOMCT_UNORDERED_RELIABLE; | 168 channel_type = DCOMCT_UNORDERED_RELIABLE; |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 rtc::ByteBuffer buffer( | 172 rtc::ByteBuffer buffer( |
173 NULL, 20 + label.length() + config.protocol.length(), | 173 NULL, 20 + label.length() + config.protocol.length(), |
174 rtc::ByteBuffer::ORDER_NETWORK); | 174 rtc::ByteBuffer::ORDER_NETWORK); |
175 buffer.WriteUInt8(DATA_CHANNEL_OPEN_MESSAGE_TYPE); | 175 buffer.WriteUInt8(DATA_CHANNEL_OPEN_MESSAGE_TYPE); |
176 buffer.WriteUInt8(channel_type); | 176 buffer.WriteUInt8(channel_type); |
177 buffer.WriteUInt16(priority); | 177 buffer.WriteUInt16(priority); |
178 buffer.WriteUInt32(reliability_param); | 178 buffer.WriteUInt32(reliability_param); |
179 buffer.WriteUInt16(static_cast<uint16>(label.length())); | 179 buffer.WriteUInt16(static_cast<uint16_t>(label.length())); |
180 buffer.WriteUInt16(static_cast<uint16>(config.protocol.length())); | 180 buffer.WriteUInt16(static_cast<uint16_t>(config.protocol.length())); |
181 buffer.WriteString(label); | 181 buffer.WriteString(label); |
182 buffer.WriteString(config.protocol); | 182 buffer.WriteString(config.protocol); |
183 payload->SetData(buffer.Data(), buffer.Length()); | 183 payload->SetData(buffer.Data(), buffer.Length()); |
184 return true; | 184 return true; |
185 } | 185 } |
186 | 186 |
187 void WriteDataChannelOpenAckMessage(rtc::Buffer* payload) { | 187 void WriteDataChannelOpenAckMessage(rtc::Buffer* payload) { |
188 rtc::ByteBuffer buffer(rtc::ByteBuffer::ORDER_NETWORK); | 188 rtc::ByteBuffer buffer(rtc::ByteBuffer::ORDER_NETWORK); |
189 buffer.WriteUInt8(DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE); | 189 buffer.WriteUInt8(DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE); |
190 payload->SetData(buffer.Data(), buffer.Length()); | 190 payload->SetData(buffer.Data(), buffer.Length()); |
191 } | 191 } |
192 } // namespace webrtc | 192 } // namespace webrtc |
OLD | NEW |