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

Function parse_wireaddr_internal

common/wireaddr.c:638–780  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

636}
637
638const char *parse_wireaddr_internal(const tal_t *ctx,
639 const char *arg,
640 u16 default_port,
641 bool dns_lookup_ok,
642 struct wireaddr_internal *addr)
643{
644 u16 splitport;
645 char *ip;
646 char *service_addr;
647 const char *err;
648 bool needed_dns, is_websocket;
649
650 /* Addresses starting with '/' are local socket paths */
651 if (arg[0] == '/') {
652 addr->itype = ADDR_INTERNAL_SOCKNAME;
653
654 /* Check if the path is too long */
655 if (strlen(arg) >= sizeof(addr->u.sockname))
656 return "Socket name too long";
657
658 /* Zero it out for passing across the wire */
659 memset(addr->u.sockname, 0, sizeof(addr->u.sockname));
660 strcpy(addr->u.sockname, arg);
661 return NULL;
662 }
663
664 /* 'autotor:' is a special prefix meaning talk to Tor to create
665 * an onion address. */
666 if (strstarts(arg, "autotor:")) {
667 addr->itype = ADDR_INTERNAL_AUTOTOR;
668 addr->u.torservice.port = chainparams_get_ln_port(chainparams);
669 /* Format is separated by slash. */
670 char **parts = tal_strsplit(tmpctx, arg, "/", STR_EMPTY_OK);
671
672 for (size_t i = 1; i < tal_count(parts)-1; i++) {
673 if (strstarts(parts[i], "torport=")) {
674 char *endp = NULL;
675 addr->u.torservice.port = strtol(parts[i]+strlen("torport="), &endp, 10);
676 if (addr->u.torservice.port <= 0 || *endp != '\0') {
677 return "Bad :torport: number";
678 }
679 } else {
680 return tal_fmt(ctx, "unknown tor arg %s", parts[i]);
681 }
682 }
683
684 service_addr = tal_fmt(tmpctx, "%s", parts[0] + strlen("autotor:"));
685 return parse_wireaddr(ctx, service_addr, 9051,
686 dns_lookup_ok ? NULL : &needed_dns,
687 &addr->u.torservice.address);
688 }
689
690 /* 'statictor:' is a special prefix meaning talk to Tor to create
691 * an static onion address from a blob or node id */
692 if (strstarts(arg, "statictor:")) {
693 bool use_magic_blob = true;
694 addr->itype = ADDR_INTERNAL_STATICTOR;
695 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