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

Function json_connect

lightningd/connect_control.c:167–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167static 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;

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
parse_wireaddr_internalFunction · 0.85
parse_wireaddrFunction · 0.85
peer_by_idFunction · 0.85
fmt_wireaddr_internalFunction · 0.85
connect_cmd_succeedFunction · 0.85
peer_channels_cleanupFunction · 0.85
new_connectFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70

Tested by

no test coverage detected