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

Function json_connect

lightningd/connect_control.c:164–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164static struct command_result *json_connect(struct command *cmd,
165 const char *buffer,
166 const jsmntok_t *obj UNNEEDED,
167 const jsmntok_t *params)
168{
169 struct wireaddr_internal *addr;
170 const char *err_msg;
171 struct id_and_addr id_addr;
172 struct peer *peer;
173
174 id_addr.host = NULL;
175 id_addr.port = NULL;
176 if (!param_check(cmd, buffer, params,
177 p_req("id", param_id_maybe_addr, &id_addr),
178 p_opt("host", param_id_addr_string, &id_addr.host),
179 p_opt("port", param_id_addr_u16, &id_addr.port),
180 NULL))
181 return command_param_failed();
182
183 /* If we have a host, convert */
184 if (id_addr.host) {
185 u16 port = id_addr.port ? *id_addr.port : chainparams_get_ln_port(chainparams);
186 addr = tal(cmd, struct wireaddr_internal);
187 err_msg = parse_wireaddr_internal(tmpctx, id_addr.host, port,
188 !cmd->ld->always_use_proxy
189 && !cmd->ld->pure_tor_setup, addr);
190 if (err_msg) {
191 return command_fail(cmd, LIGHTNINGD,
192 "Host %s:%u not valid: %s",
193 id_addr.host, port, err_msg);
194 }
195 /* Check they didn't specify some weird type! */
196 switch (addr->itype) {
197 case ADDR_INTERNAL_SOCKNAME:
198 case ADDR_INTERNAL_WIREADDR:
199 /* Can happen if we're disable DNS */
200 case ADDR_INTERNAL_FORPROXY:
201 break;
202 case ADDR_INTERNAL_ALLPROTO:
203 case ADDR_INTERNAL_AUTOTOR:
204 case ADDR_INTERNAL_STATICTOR:
205 return command_fail(cmd, LIGHTNINGD,
206 "Host %s:%u not a simple type",
207 id_addr.host, port);
208 }
209 } else {
210 addr = NULL;
211 /* Port without host name? */
212 if (id_addr.port)
213 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
214 "Can't specify port without host");
215 }
216
217 if (command_check_only(cmd))
218 return command_check_done(cmd);
219
220 /* If we know about peer, see if it's already connected. */
221 peer = peer_by_id(cmd->ld, &id_addr.id);

Callers

nothing calls this directly

Calls 14

param_checkFunction · 0.85
parse_wireaddr_internalFunction · 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
subd_send_msgFunction · 0.70

Tested by

no test coverage detected