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

Function parse_wireaddr_internal

common/wireaddr.c:616–758  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

614}
615
616const char *parse_wireaddr_internal(const tal_t *ctx,
617 const char *arg,
618 u16 default_port,
619 bool dns_lookup_ok,
620 struct wireaddr_internal *addr)
621{
622 u16 splitport;
623 char *ip;
624 char *service_addr;
625 const char *err;
626 bool needed_dns, is_websocket;
627
628 /* Addresses starting with '/' are local socket paths */
629 if (arg[0] == '/') {
630 addr->itype = ADDR_INTERNAL_SOCKNAME;
631
632 /* Check if the path is too long */
633 if (strlen(arg) >= sizeof(addr->u.sockname))
634 return "Socket name too long";
635
636 /* Zero it out for passing across the wire */
637 memset(addr->u.sockname, 0, sizeof(addr->u.sockname));
638 strcpy(addr->u.sockname, arg);
639 return NULL;
640 }
641
642 /* 'autotor:' is a special prefix meaning talk to Tor to create
643 * an onion address. */
644 if (strstarts(arg, "autotor:")) {
645 addr->itype = ADDR_INTERNAL_AUTOTOR;
646 addr->u.torservice.port = chainparams_get_ln_port(chainparams);
647 /* Format is separated by slash. */
648 char **parts = tal_strsplit(tmpctx, arg, "/", STR_EMPTY_OK);
649
650 for (size_t i = 1; i < tal_count(parts)-1; i++) {
651 if (strstarts(parts[i], "torport=")) {
652 char *endp = NULL;
653 addr->u.torservice.port = strtol(parts[i]+strlen("torport="), &endp, 10);
654 if (addr->u.torservice.port <= 0 || *endp != '\0') {
655 return "Bad :torport: number";
656 }
657 } else {
658 return tal_fmt(ctx, "unknown tor arg %s", parts[i]);
659 }
660 }
661
662 service_addr = tal_fmt(tmpctx, "%s", parts[0] + strlen("autotor:"));
663 return parse_wireaddr(ctx, service_addr, 9051,
664 dns_lookup_ok ? NULL : &needed_dns,
665 &addr->u.torservice.address);
666 }
667
668 /* 'statictor:' is a special prefix meaning talk to Tor to create
669 * an static onion address from a blob or node id */
670 if (strstarts(arg, "statictor:")) {
671 bool use_magic_blob = true;
672 addr->itype = ADDR_INTERNAL_STATICTOR;
673 addr->u.torservice.port = chainparams_get_ln_port(chainparams);

Callers 9

wallet_peer_loadFunction · 0.85
test_wallet_outputsFunction · 0.85
test_channel_crudFunction · 0.85
opt_add_addr_withtypeFunction · 0.85
json_connectFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 5

parse_wireaddrFunction · 0.85
tal_freeFunction · 0.85
wireaddr_from_unresolvedFunction · 0.85
chainparams_get_ln_portFunction · 0.50

Tested by 5

test_wallet_outputsFunction · 0.68
test_channel_crudFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68