This initializes a fresh io_conn by setting it to io_connect to the * destination */
| 680 | /* This initializes a fresh io_conn by setting it to io_connect to the |
| 681 | * destination */ |
| 682 | static struct io_plan *conn_init(struct io_conn *conn, |
| 683 | struct connecting *connect) |
| 684 | { |
| 685 | /*~ I generally dislike the pattern of "set to NULL, assert if NULL at |
| 686 | * bottom". On -O2 and above the compiler will warn you at compile time |
| 687 | * if a there is a path by which the variable is not set, which is always |
| 688 | * preferable to a runtime assertion. In this case, it's the best way |
| 689 | * to use the "enum in a switch" trick to make sure we handle all enum |
| 690 | * cases, so I use it. */ |
| 691 | struct addrinfo *ai = NULL; |
| 692 | const struct wireaddr_internal *addr = &connect->addrs[connect->addrnum]; |
| 693 | |
| 694 | switch (addr->itype) { |
| 695 | case ADDR_INTERNAL_SOCKNAME: |
| 696 | ai = wireaddr_internal_to_addrinfo(tmpctx, addr); |
| 697 | break; |
| 698 | case ADDR_INTERNAL_ALLPROTO: |
| 699 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 700 | "Can't connect to all protocols"); |
| 701 | break; |
| 702 | case ADDR_INTERNAL_AUTOTOR: |
| 703 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 704 | "Can't connect to autotor address"); |
| 705 | break; |
| 706 | case ADDR_INTERNAL_STATICTOR: |
| 707 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 708 | "Can't connect to statictor address"); |
| 709 | break; |
| 710 | case ADDR_INTERNAL_FORPROXY: |
| 711 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 712 | "Can't connect to forproxy address"); |
| 713 | break; |
| 714 | case ADDR_INTERNAL_WIREADDR: |
| 715 | /* DNS should have been resolved before */ |
| 716 | assert(addr->u.wireaddr.type != ADDR_TYPE_DNS); |
| 717 | /* If it was a Tor address, we wouldn't be here. */ |
| 718 | assert(!is_toraddr((char*)addr->u.wireaddr.addr)); |
| 719 | ai = wireaddr_to_addrinfo(tmpctx, &addr->u.wireaddr); |
| 720 | break; |
| 721 | } |
| 722 | assert(ai); |
| 723 | |
| 724 | io_set_finish(conn, destroy_io_conn, connect); |
| 725 | return io_connect(conn, ai, connection_out, connect); |
| 726 | } |
| 727 | |
| 728 | /* This initializes a fresh io_conn by setting it to io_connect to the |
| 729 | * SOCKS proxy, as handled in tor.c. */ |
nothing calls this directly
no test coverage detected