mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
connectd: ensure htables are always tal objects.
We want to change the htable allocator to use tal, which will need this. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
4a570c9419
commit
81e57dce52
@ -208,7 +208,7 @@ void destroy_peer(struct peer *peer)
|
|||||||
{
|
{
|
||||||
assert(!peer->draining);
|
assert(!peer->draining);
|
||||||
|
|
||||||
if (!peer_htable_del(&peer->daemon->peers, peer))
|
if (!peer_htable_del(peer->daemon->peers, peer))
|
||||||
abort();
|
abort();
|
||||||
|
|
||||||
/* Tell gossipd to stop asking this peer gossip queries */
|
/* Tell gossipd to stop asking this peer gossip queries */
|
||||||
@ -257,7 +257,7 @@ static struct peer *new_peer(struct daemon *daemon,
|
|||||||
|
|
||||||
/* Now we own it */
|
/* Now we own it */
|
||||||
tal_steal(peer, peer->to_peer);
|
tal_steal(peer, peer->to_peer);
|
||||||
peer_htable_add(&daemon->peers, peer);
|
peer_htable_add(daemon->peers, peer);
|
||||||
tal_add_destructor(peer, destroy_peer);
|
tal_add_destructor(peer, destroy_peer);
|
||||||
|
|
||||||
return peer;
|
return peer;
|
||||||
@ -282,7 +282,7 @@ struct io_plan *peer_connected(struct io_conn *conn,
|
|||||||
bool option_gossip_queries;
|
bool option_gossip_queries;
|
||||||
|
|
||||||
/* We remove any previous connection immediately, on the assumption it's dead */
|
/* We remove any previous connection immediately, on the assumption it's dead */
|
||||||
peer = peer_htable_get(&daemon->peers, id);
|
peer = peer_htable_get(daemon->peers, id);
|
||||||
if (peer)
|
if (peer)
|
||||||
tal_free(peer);
|
tal_free(peer);
|
||||||
|
|
||||||
@ -1724,7 +1724,7 @@ static void try_connect_peer(struct daemon *daemon,
|
|||||||
struct connecting *connect;
|
struct connecting *connect;
|
||||||
|
|
||||||
/* Already existing? Must have crossed over, it'll know soon. */
|
/* Already existing? Must have crossed over, it'll know soon. */
|
||||||
if (peer_htable_get(&daemon->peers, id))
|
if (peer_htable_get(daemon->peers, id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* If we're trying to connect it right now, that's OK. */
|
/* If we're trying to connect it right now, that's OK. */
|
||||||
@ -1827,7 +1827,7 @@ static void peer_discard(struct daemon *daemon, const u8 *msg)
|
|||||||
|
|
||||||
/* We should stay in sync with lightningd, but this can happen
|
/* We should stay in sync with lightningd, but this can happen
|
||||||
* under stress. */
|
* under stress. */
|
||||||
peer = peer_htable_get(&daemon->peers, &id);
|
peer = peer_htable_get(daemon->peers, &id);
|
||||||
if (!peer)
|
if (!peer)
|
||||||
return;
|
return;
|
||||||
/* If it's reconnected already, it will learn soon. */
|
/* If it's reconnected already, it will learn soon. */
|
||||||
@ -1852,7 +1852,7 @@ static void peer_final_msg(struct io_conn *conn,
|
|||||||
|
|
||||||
/* This can happen if peer hung up on us (or wrong counter
|
/* This can happen if peer hung up on us (or wrong counter
|
||||||
* if it reconnected). */
|
* if it reconnected). */
|
||||||
peer = peer_htable_get(&daemon->peers, &id);
|
peer = peer_htable_get(daemon->peers, &id);
|
||||||
if (peer && peer->counter == counter)
|
if (peer && peer->counter == counter)
|
||||||
multiplex_final_msg(peer, take(finalmsg));
|
multiplex_final_msg(peer, take(finalmsg));
|
||||||
}
|
}
|
||||||
@ -1868,7 +1868,7 @@ static void dev_connect_memleak(struct daemon *daemon, const u8 *msg)
|
|||||||
|
|
||||||
/* Now delete daemon and those which it has pointers to. */
|
/* Now delete daemon and those which it has pointers to. */
|
||||||
memleak_scan_obj(memtable, daemon);
|
memleak_scan_obj(memtable, daemon);
|
||||||
memleak_scan_htable(memtable, &daemon->peers.raw);
|
memleak_scan_htable(memtable, &daemon->peers->raw);
|
||||||
|
|
||||||
found_leak = dump_memleak(memtable, memleak_status_broken);
|
found_leak = dump_memleak(memtable, memleak_status_broken);
|
||||||
daemon_conn_send(daemon->master,
|
daemon_conn_send(daemon->master,
|
||||||
@ -1995,7 +1995,7 @@ static struct io_plan *recv_gossip(struct io_conn *conn,
|
|||||||
status_failed(STATUS_FAIL_GOSSIP_IO, "Unknown msg %i",
|
status_failed(STATUS_FAIL_GOSSIP_IO, "Unknown msg %i",
|
||||||
fromwire_peektype(msg));
|
fromwire_peektype(msg));
|
||||||
|
|
||||||
peer = peer_htable_get(&daemon->peers, &dst);
|
peer = peer_htable_get(daemon->peers, &dst);
|
||||||
if (peer)
|
if (peer)
|
||||||
inject_peer_msg(peer, take(gossip_msg));
|
inject_peer_msg(peer, take(gossip_msg));
|
||||||
|
|
||||||
@ -2007,7 +2007,7 @@ static struct io_plan *recv_gossip(struct io_conn *conn,
|
|||||||
#if DEVELOPER
|
#if DEVELOPER
|
||||||
static void memleak_daemon_cb(struct htable *memtable, struct daemon *daemon)
|
static void memleak_daemon_cb(struct htable *memtable, struct daemon *daemon)
|
||||||
{
|
{
|
||||||
memleak_scan_htable(memtable, &daemon->peers.raw);
|
memleak_scan_htable(memtable, &daemon->peers->raw);
|
||||||
}
|
}
|
||||||
#endif /* DEVELOPER */
|
#endif /* DEVELOPER */
|
||||||
|
|
||||||
@ -2023,7 +2023,8 @@ int main(int argc, char *argv[])
|
|||||||
/* Allocate and set up our simple top-level structure. */
|
/* Allocate and set up our simple top-level structure. */
|
||||||
daemon = tal(NULL, struct daemon);
|
daemon = tal(NULL, struct daemon);
|
||||||
daemon->connection_counter = 1;
|
daemon->connection_counter = 1;
|
||||||
peer_htable_init(&daemon->peers);
|
daemon->peers = tal(daemon, struct peer_htable);
|
||||||
|
peer_htable_init(daemon->peers);
|
||||||
memleak_add_helper(daemon, memleak_daemon_cb);
|
memleak_add_helper(daemon, memleak_daemon_cb);
|
||||||
list_head_init(&daemon->connecting);
|
list_head_init(&daemon->connecting);
|
||||||
timers_init(&daemon->timers, time_mono());
|
timers_init(&daemon->timers, time_mono());
|
||||||
|
@ -142,7 +142,7 @@ struct daemon {
|
|||||||
|
|
||||||
/* Peers that we've handed to `lightningd`, which it hasn't told us
|
/* Peers that we've handed to `lightningd`, which it hasn't told us
|
||||||
* have disconnected. */
|
* have disconnected. */
|
||||||
struct peer_htable peers;
|
struct peer_htable *peers;
|
||||||
|
|
||||||
/* Peers we are trying to reach */
|
/* Peers we are trying to reach */
|
||||||
struct list_head connecting;
|
struct list_head connecting;
|
||||||
|
@ -592,7 +592,7 @@ void send_custommsg(struct daemon *daemon, const u8 *msg)
|
|||||||
master_badmsg(WIRE_CONNECTD_CUSTOMMSG_OUT, msg);
|
master_badmsg(WIRE_CONNECTD_CUSTOMMSG_OUT, msg);
|
||||||
|
|
||||||
/* Races can happen: this might be gone by now. */
|
/* Races can happen: this might be gone by now. */
|
||||||
peer = peer_htable_get(&daemon->peers, &id);
|
peer = peer_htable_get(daemon->peers, &id);
|
||||||
if (peer)
|
if (peer)
|
||||||
inject_peer_msg(peer, take(custommsg));
|
inject_peer_msg(peer, take(custommsg));
|
||||||
}
|
}
|
||||||
@ -1242,7 +1242,7 @@ void peer_connect_subd(struct daemon *daemon, const u8 *msg, int fd)
|
|||||||
master_badmsg(WIRE_CONNECTD_PEER_CONNECT_SUBD, msg);
|
master_badmsg(WIRE_CONNECTD_PEER_CONNECT_SUBD, msg);
|
||||||
|
|
||||||
/* Races can happen: this might be gone by now (or reconnected!). */
|
/* Races can happen: this might be gone by now (or reconnected!). */
|
||||||
peer = peer_htable_get(&daemon->peers, &id);
|
peer = peer_htable_get(daemon->peers, &id);
|
||||||
if (!peer || peer->counter != counter) {
|
if (!peer || peer->counter != counter) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return;
|
return;
|
||||||
@ -1276,7 +1276,7 @@ void send_manual_ping(struct daemon *daemon, const u8 *msg)
|
|||||||
if (!fromwire_connectd_ping(msg, &id, &num_pong_bytes, &len))
|
if (!fromwire_connectd_ping(msg, &id, &num_pong_bytes, &len))
|
||||||
master_badmsg(WIRE_CONNECTD_PING, msg);
|
master_badmsg(WIRE_CONNECTD_PING, msg);
|
||||||
|
|
||||||
peer = peer_htable_get(&daemon->peers, &id);
|
peer = peer_htable_get(daemon->peers, &id);
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
daemon_conn_send(daemon->master,
|
daemon_conn_send(daemon->master,
|
||||||
take(towire_connectd_ping_reply(NULL,
|
take(towire_connectd_ping_reply(NULL,
|
||||||
|
@ -29,7 +29,7 @@ void onionmsg_req(struct daemon *daemon, const u8 *msg)
|
|||||||
|
|
||||||
/* Even though lightningd checks for valid ids, there's a race
|
/* Even though lightningd checks for valid ids, there's a race
|
||||||
* where it might vanish before we read this command. */
|
* where it might vanish before we read this command. */
|
||||||
peer = peer_htable_get(&daemon->peers, &id);
|
peer = peer_htable_get(daemon->peers, &id);
|
||||||
if (peer) {
|
if (peer) {
|
||||||
u8 *omsg = towire_onion_message(NULL, &blinding, onionmsg);
|
u8 *omsg = towire_onion_message(NULL, &blinding, onionmsg);
|
||||||
inject_peer_msg(peer, take(omsg));
|
inject_peer_msg(peer, take(omsg));
|
||||||
@ -86,7 +86,7 @@ void handle_onion_message(struct daemon *daemon,
|
|||||||
|
|
||||||
/* FIXME: Handle short_channel_id! */
|
/* FIXME: Handle short_channel_id! */
|
||||||
node_id_from_pubkey(&next_node_id, &next_node);
|
node_id_from_pubkey(&next_node_id, &next_node);
|
||||||
next_peer = peer_htable_get(&daemon->peers, &next_node_id);
|
next_peer = peer_htable_get(daemon->peers, &next_node_id);
|
||||||
if (!next_peer) {
|
if (!next_peer) {
|
||||||
status_peer_debug(&peer->id,
|
status_peer_debug(&peer->id,
|
||||||
"onion msg: unknown next peer %s",
|
"onion msg: unknown next peer %s",
|
||||||
|
Loading…
Reference in New Issue
Block a user