mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-03 21:24:22 +01:00
daemon: command to connect
Now we can connect two daemons to each other. Who both say Hello! and close. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -188,6 +188,7 @@ static const struct json_command *cmdlist[] = {
|
||||
&help_command,
|
||||
&stop_command,
|
||||
&getlog_command,
|
||||
&connect_command,
|
||||
/* Developer/debugging options. */
|
||||
&echo_command,
|
||||
};
|
||||
|
||||
@@ -43,5 +43,6 @@ void json_notify(struct json_connection *jcon, const char *result);
|
||||
void setup_jsonrpc(struct lightningd_state *state, const char *rpc_filename);
|
||||
|
||||
/* Commands (from other files) */
|
||||
extern const struct json_command connect_command;
|
||||
|
||||
#endif /* LIGHTNING_DAEMON_JSONRPC_H */
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "dns.h"
|
||||
#include "jsonrpc.h"
|
||||
#include "lightningd.h"
|
||||
#include "log.h"
|
||||
#include "peer.h"
|
||||
@@ -158,3 +160,36 @@ void setup_listeners(struct lightningd_state *state, unsigned int portnum)
|
||||
if (fd1 < 0 && fd2 < 0)
|
||||
fatal("Could not bind to a network address");
|
||||
}
|
||||
|
||||
static char *json_connect(struct json_connection *jcon,
|
||||
const jsmntok_t *params,
|
||||
struct json_result *response)
|
||||
{
|
||||
jsmntok_t *host, *port;
|
||||
const char *hoststr, *portstr;
|
||||
|
||||
json_get_params(jcon->buffer, params, "host", &host, "port", &port,
|
||||
NULL);
|
||||
|
||||
if (!host || !port)
|
||||
return "Need host and port";
|
||||
|
||||
hoststr = tal_strndup(response, jcon->buffer + host->start,
|
||||
host->end - host->start);
|
||||
portstr = tal_strndup(response, jcon->buffer + port->start,
|
||||
port->end - port->start);
|
||||
if (!dns_resolve_and_connect(jcon->state, hoststr, portstr,
|
||||
peer_connected_out))
|
||||
return "DNS failed";
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_object_end(response);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const struct json_command connect_command = {
|
||||
"connect",
|
||||
json_connect,
|
||||
"Connect to a {host} at {port}",
|
||||
"Returns an empty result (meaning connection in progress)"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user