OverviewFilesCommitsIssuesDocsReleasesPeers

hyperswarm-peer commits / 5e13f1f

swarmd-probe: offer the frame until it is taken, not once on a timer
The probe sent exactly once, eight seconds into its window, whether or not a peer existed. That passed on a local testnet — where the mesh forms in under a second — and was a coin toss on the public DHT, because a frame offered before the remote opens the channel is discarded by protomux. Now that the daemon answers `accepted` truthfully, that answer is the trigger: re-offer once a second until it is taken. Measured with the sender started 25 seconds BEFORE the receiver: 26 attempts refused, then accepted, then the frame crossed. The old probe would have fired at second 8 and been told it succeeded. Also removed a tautology in the read loop (`m.bytes_len == 0` on a struct memset to zero one line above), and a pure sender now exits on what it knows — whether its frame was accepted — instead of reporting "no message received" about a reply it never expected. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
5e13f1fcfcae62616da7bd59acee95be8ce1a83c
by plankatron <fleeky@gmail.com> · 2026-09-10T18:45:22.000Z

Changed files (1) +37 -13

swarmd/tools/swarmd_probe.cpp +37 -13
……@@ -104,22 +104,29 @@ int main(int argc, char **argv) {
104104 printf("joined topic, opened %s\n", proto);
105105 fflush(stdout);
106106
107 // ⛔ DO NOT SEND ON A TIMER. The first version fired once, eight seconds in,
108 // whether or not a peer existed — and a send onto a channel the remote has
109 // not opened yet is discarded by protomux. It worked on a local testnet,
110 // where the mesh forms in under a second, and would have been a coin toss on
111 // the public DHT. The daemon now answers `accepted` truthfully, so the right
112 // trigger is that answer: keep offering the frame until it is taken.
107113 const time_t deadline = time(nullptr) + seconds;
108 bool sent = false;
114 const uint64_t FIRST_SEND_ID = 4;
115 uint64_t next_send_id = FIRST_SEND_ID;
116 bool send_accepted = false;
117 time_t last_attempt = 0;
109118 std::vector<uint8_t> in;
110119 while (time(nullptr) < deadline) {
111 if (send_text && !sent && time(nullptr) > deadline - seconds + 8) {
120 if (send_text && !send_accepted && time(nullptr) != last_attempt) {
121 last_attempt = time(nullptr);
112122 swarmd_send_request_t sr;
113123 memset(&sr, 0, sizeof(sr));
114124 sr.channel = 1; sr.slot = 0; sr.target = 0;
115125 sr.bytes = (uint8_t *)send_text;
116126 sr.bytes_len = strlen(send_text);
117 if (swarmd_encode_send(4, &sr, &buf, &len) >= 0) {
127 if (swarmd_encode_send(next_send_id++, &sr, &buf, &len) >= 0) {
118128 send_frame(fd, buf, len);
119 printf("sent: %s\n", send_text);
120 fflush(stdout);
121129 }
122 sent = true;
123130 }
124131
125132 uint8_t tmp[65536];
……@@ -138,12 +145,22 @@ int main(int argc, char **argv) {
138145 compact_state_t st = { 0, n, in.data() + 4 };
139146 rpc_message_t msg;
140147 if (rpc_decode_message(&st, &msg) >= 0) {
141 swarmd_message_t m;
142 hrpc_error_t err;
143 memset(&m, 0, sizeof(m));
144 // An event carries no reply; decoding it as on-message tells us
145 // whether that is what arrived.
146 if (msg.type == rpc_request && m.bytes_len == 0) {
148 if (msg.type == rpc_response && msg.id >= FIRST_SEND_ID) {
149 // The answer to one of our send attempts. `accepted` is the
150 // daemon saying it had an open channel to put the frame on.
151 swarmd_send_result_t res;
152 memset(&res, 0, sizeof(res));
153 compact_state_t body = { 0, msg.len, msg.data };
154 if (swarmd_send_result_decode(&body, &res) >= 0 && res.accepted &&
155 !send_accepted) {
156 send_accepted = true;
157 printf("sent (accepted after %d attempt%s): %s\n",
158 (int)(msg.id - FIRST_SEND_ID + 1),
159 msg.id == FIRST_SEND_ID ? "" : "s", send_text);
160 fflush(stdout);
161 }
162 } else if (msg.type == rpc_request) {
163 // An event: no reply, and dispatching it tells us which one.
147164 swarmd_hrpc_handlers_t h;
148165 memset(&h, 0, sizeof(h));
149166 static std::string got;
……@@ -161,12 +178,19 @@ int main(int argc, char **argv) {
161178 return 0;
162179 }
163180 }
164 (void)err;
165181 }
166182 in.erase(in.begin(), in.begin() + 4 + n);
167183 }
168184 }
169185
186 // A pure sender has nothing to receive, so say what it actually knows.
187 if (send_text) {
188 printf(send_accepted ? "sent, never answered\n"
189 : "the daemon never accepted the frame — no channel was "
190 "open on any peer\n");
191 close(fd);
192 return send_accepted ? 0 : 1;
193 }
170194 printf("no message received\n");
171195 close(fd);
172196 return 1;