MCPcopy Create free account
hub / github.com/defold/defold / BuildServiceInstanceName

Function BuildServiceInstanceName

engine/engine/src/engine_service_private.h:133–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131 }
132
133 static inline void BuildServiceInstanceName(const char* local_address, const char* port_text, const char* suffix_text, char* out, uint32_t out_size)
134 {
135 if (out_size == 0)
136 return;
137
138 char sanitized_address[MDNS_MAX_LABEL_LENGTH + 1];
139 SanitizeMDNSLabel(local_address, "localhost", false, 0, sanitized_address, sizeof(sanitized_address));
140
141 static const char prefix[] = "defold";
142 const uint32_t prefix_length = (uint32_t) strlen(prefix);
143 uint32_t max_label_length = out_size - 1;
144 if (max_label_length > MDNS_MAX_LABEL_LENGTH)
145 max_label_length = MDNS_MAX_LABEL_LENGTH;
146
147 uint32_t port_component_length = 0;
148 if (port_text && port_text[0])
149 {
150 port_component_length = 1 + (uint32_t) strlen(port_text);
151 if (prefix_length + port_component_length > max_label_length)
152 port_component_length = 0;
153 }
154
155 // The startup suffix is formatted as 8 lowercase hex digits.
156 const uint32_t suffix_component_length = (suffix_text && suffix_text[0]) ? 9 : 0;
157
158 // Spend any remaining label budget on the address and drop it entirely
159 // before we would emit a dangling "defold-" separator.
160 uint32_t max_address_length = 0;
161 if (prefix_length + port_component_length + suffix_component_length + 1 < max_label_length)
162 max_address_length = max_label_length - prefix_length - port_component_length - suffix_component_length - 1;
163
164 if ((uint32_t) strlen(sanitized_address) > max_address_length)
165 sanitized_address[max_address_length] = 0;
166
167 char address_component[MDNS_MAX_LABEL_LENGTH + 2];
168 address_component[0] = 0;
169 if (sanitized_address[0])
170 dmSnPrintf(address_component, sizeof(address_component), "-%s", sanitized_address);
171
172 char port_component[MDNS_MAX_LABEL_LENGTH + 2];
173 port_component[0] = 0;
174 if (port_component_length != 0)
175 dmSnPrintf(port_component, sizeof(port_component), "-%s", port_text);
176
177 char suffix_component[MDNS_MAX_LABEL_LENGTH + 2];
178 suffix_component[0] = 0;
179 if (suffix_component_length != 0)
180 dmSnPrintf(suffix_component, sizeof(suffix_component), "-%s", suffix_text);
181
182 dmSnPrintf(out, out_size, "%s%s%s%s", prefix, address_component, port_component, suffix_component);
183 }
184
185 static inline uint64_t GetDiscoveryRetryDelayUsec(uint32_t failure_count)
186 {

Callers 2

InitMethod · 0.85
TEST_FFunction · 0.85

Calls 2

SanitizeMDNSLabelFunction · 0.85
dmSnPrintfFunction · 0.85

Tested by 1

TEST_FFunction · 0.68