MCPcopy Create free account
hub / github.com/attermann/microReticulum / Resource

Method Resource

src/microReticulum/Resource.cpp:161–216  ·  view source on GitHub ↗

Minimal constructor — stores the payload and link, sets baseline state, but performs NO network work. Use the fluent setters to configure optional parameters, then call start() to kick off the transfer (initiator side). The receiver side is built via Resource::accept(), which uses this constructor and then populates per-advertisement fields directly.

Source from the content-addressed store, hash-verified

159// The receiver side is built via Resource::accept(), which uses this
160// constructor and then populates per-advertisement fields directly.
161Resource::Resource(const Bytes& data, const Link& link) :
162 _object(new ResourceData(link))
163{
164 assert(_object);
165 MEM("Resource object created");
166
167 // Stash the pending payload until start() is called (initiator side).
168 // For the receiver branch (accept() with empty data) this stays empty.
169 _object->_data = data;
170
171 // Metadata handling — auto-compress and metadata serialisation are
172 // not yet supported on the C++ port (see plan: "no bz2 on MCU";
173 // metadata support deferred). Always emit uncompressed, no metadata.
174 _object->_metadata = {Bytes::NONE};
175 _object->_has_metadata = false;
176 _object->_metadata_size = 0;
177
178 _object->_status = Type::Resource::NONE;
179 _object->_link = link;
180
181 // SDU: mirror Python Resource.__init__ (Resource.py:337-340)
182 // Use the non-const Link stored in _object->_link since Link::get_mtu/
183 // get_mdu are not const-qualified (they assert _object via pimpl).
184 if (_object->_link.get_mtu()) {
185 _object->_sdu = static_cast<uint16_t>(_object->_link.get_mtu() - Type::Reticulum::HEADER_MAXSIZE - Type::Reticulum::IFAC_MIN_SIZE);
186 }
187 else if (_object->_link.get_mdu()) {
188 _object->_sdu = _object->_link.get_mdu();
189 }
190 else {
191 _object->_sdu = Type::Resource::SDU;
192 }
193
194 _object->_max_retries = Type::Resource::MAX_RETRIES;
195 _object->_max_adv_retries = Type::Resource::MAX_ADV_RETRIES;
196 _object->_retries_left = _object->_max_retries;
197 _object->_timeout_factor = link.traffic_timeout_factor();
198 _object->_part_timeout_factor = Type::Resource::PART_TIMEOUT_FACTOR;
199 _object->_sender_grace_time = Type::Resource::SENDER_GRACE_TIME;
200 _object->_auto_compress_option = true; // default; override via auto_compress()
201 _object->_auto_compress = false; // bz2 not available on MCU; see plan
202 _object->_auto_compress_limit = Type::Resource::AUTO_COMPRESS_MAX_SIZE;
203 _object->_max_decompressed_size = Type::Resource::AUTO_COMPRESS_MAX_SIZE;
204 _object->_receiver_min_consecutive_height = 0;
205
206 // Default timeout derived from the link; timeout() setter overrides.
207 _object->_timeout = link.rtt() * link.traffic_timeout_factor();
208
209 // Always single-segment, no compression, no metadata on the C++ port.
210 _object->_total_segments = 1;
211 _object->_segment_index = 1;
212 _object->_split = false;
213
214 // _initiator is finalised by start() (true) or by accept() (false).
215 _object->_initiator = false;
216}
217
218// Compact deprecated form — delegates to minimal constructor + fluent setters

Callers

nothing calls this directly

Calls 6

is_responseMethod · 0.95
get_mtuMethod · 0.80
get_mduMethod · 0.80
rttMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected