MCPcopy Create free account
hub / github.com/ElementsProject/lightning / tor_fixed_service

Function tor_fixed_service

connectd/tor_autoservice.c:296–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294}
295
296struct wireaddr *tor_fixed_service(const tal_t *ctx,
297 const struct wireaddr_internal *tor_serviceaddr,
298 const char *tor_password,
299 const char *blob,
300 const struct wireaddr *bind,
301 const u8 index)
302{
303 int fd;
304 const struct wireaddr *laddr;
305 struct wireaddr *onion;
306 struct addrinfo *ai_tor;
307 struct rbuf rbuf;
308 char *buffer;
309
310 laddr = bind;
311 ai_tor = wireaddr_to_addrinfo(tmpctx, &tor_serviceaddr->u.torservice.address);
312
313 fd = socket(ai_tor->ai_family, SOCK_STREAM, 0);
314 if (fd < 0)
315 err(1, "Creating stream socket for Tor");
316
317 if (connect(fd, ai_tor->ai_addr, ai_tor->ai_addrlen) != 0)
318 err(1, "Connecting stream socket to Tor service");
319
320 buffer = tal_arr(tmpctx, char, rbuf_good_size(fd));
321 rbuf_init(&rbuf, fd, buffer, tal_count(buffer), buf_resize);
322
323 negotiate_auth(&rbuf, tor_password);
324
325 onion = make_fixed_onion(ctx, &rbuf, laddr, blob, tor_serviceaddr->u.torservice.port);
326 /*on the other hand we can stay connected until ln finish to keep onion alive and then vanish
327 * because when we run with Detach flag as we now do every start of LN creates a new addr while the old
328 * stays valid until reboot this might not be desired so we can also drop Detach and use the
329 * read_partial to keep it open until LN drops
330 * DO NOT CLOSE FD TO KEEP ADDRESS ALIVE AS WE DO NOT DETACH WITH STATIC ADDRESS
331 */
332 return onion;
333}

Callers 1

setup_listenersFunction · 0.85

Calls 7

wireaddr_to_addrinfoFunction · 0.85
errFunction · 0.85
rbuf_good_sizeFunction · 0.85
rbuf_initFunction · 0.85
negotiate_authFunction · 0.85
make_fixed_onionFunction · 0.85
connectFunction · 0.50

Tested by

no test coverage detected