| 165 | } |
| 166 | |
| 167 | static struct command_result *json_connect(struct command *cmd, |
| 168 | const char *buffer, |
| 169 | const jsmntok_t *obj UNNEEDED, |
| 170 | const jsmntok_t *params) |
| 171 | { |
| 172 | struct wireaddr_internal *addr; |
| 173 | const char *err_msg; |
| 174 | struct id_and_addr id_addr; |
| 175 | struct peer *peer; |
| 176 | |
| 177 | id_addr.host = NULL; |
| 178 | id_addr.port = NULL; |
| 179 | if (!param_check(cmd, buffer, params, |
| 180 | p_req("id", param_id_maybe_addr, &id_addr), |
| 181 | p_opt("host", param_id_addr_string, &id_addr.host), |
| 182 | p_opt("port", param_id_addr_u16, &id_addr.port), |
| 183 | NULL)) |
| 184 | return command_param_failed(); |
| 185 | |
| 186 | /* If we have a host, convert */ |
| 187 | if (id_addr.host) { |
| 188 | u16 port = id_addr.port ? *id_addr.port : chainparams_get_ln_port(chainparams); |
| 189 | addr = tal(cmd, struct wireaddr_internal); |
| 190 | /* Never resolve names here: getaddrinfo() would block |
| 191 | * lightningd's main loop for as long as the nameserver takes. |
| 192 | * Names come back unresolved, and connectd deals with them. */ |
| 193 | err_msg = parse_wireaddr_internal(tmpctx, id_addr.host, port, |
| 194 | false, addr); |
| 195 | if (err_msg) { |
| 196 | return command_fail(cmd, LIGHTNINGD, |
| 197 | "Host %s:%u not valid: %s", |
| 198 | id_addr.host, port, err_msg); |
| 199 | } |
| 200 | /* Check they didn't specify some weird type! */ |
| 201 | switch (addr->itype) { |
| 202 | case ADDR_INTERNAL_SOCKNAME: |
| 203 | case ADDR_INTERNAL_WIREADDR: |
| 204 | break; |
| 205 | case ADDR_INTERNAL_FORPROXY: |
| 206 | /* With a proxy, it resolves the name for us. */ |
| 207 | if (cmd->ld->always_use_proxy || cmd->ld->pure_tor_setup) |
| 208 | break; |
| 209 | /* Otherwise connectd resolves it off its io loop, |
| 210 | * just like a DNS address from a node_announcement |
| 211 | * (and honours --disable-dns). */ |
| 212 | err_msg = parse_wireaddr(tmpctx, |
| 213 | tal_fmt(tmpctx, "dns:%s", |
| 214 | addr->u.unresolved.name), |
| 215 | addr->u.unresolved.port, NULL, |
| 216 | &addr->u.wireaddr.wireaddr); |
| 217 | if (err_msg) { |
| 218 | return command_fail(cmd, LIGHTNINGD, |
| 219 | "Host %s:%u not valid: %s", |
| 220 | id_addr.host, port, err_msg); |
| 221 | } |
| 222 | addr->itype = ADDR_INTERNAL_WIREADDR; |
| 223 | addr->u.wireaddr.is_websocket = false; |
| 224 | break; |
nothing calls this directly
no test coverage detected